From f0657c0e9646b6d42261846b80e44b2f953d0ccd Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 24 Jun 2007 00:32:05 +0000 Subject: For bug #182964, replace os.rename() with portage.movefile() in cases where the parent directory might change. svn path=/main/trunk/; revision=6983 --- pym/portage/__init__.py | 6 ++++++ pym/portage/dbapi/bintree.py | 12 +++++++----- pym/portage/dbapi/vartree.py | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'pym') diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 17dc3089b..2818ae9dd 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -4011,6 +4011,12 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, expandcache={} +def _movefile(src, dest, **kwargs): + """Calls movefile and raises a PortageException if an error occurs.""" + if movefile(src, dest, **kwargs) is None: + raise portage.exception.PortageException( + "mv '%s' '%s'" % (src, dest)) + def movefile(src,dest,newmtime=None,sstat=None,mysettings=None): """moves a file from src to dest, preserving all permissions and attributes; mtime will be preserved even when moving across filesystems. Returns true on success and false on diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 3242cc158..1930bc71d 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -10,7 +10,7 @@ from portage.util import normalize_path, writemsg, writemsg_stdout from portage.versions import best, catpkgsplit, catsplit from portage.update import update_dbentries -from portage import listdir, dep_expand +from portage import dep_expand, listdir, _movefile import portage.xpak, portage.getbinpkg @@ -206,7 +206,7 @@ class binarytree(object): if e.errno != errno.EEXIST: raise del e - os.rename(tbz2path, new_path) + _movefile(tbz2path, new_path, mysettings=self.settings) self._remove_symlink(mycpv) if new_path.split(os.path.sep)[-2] == "All": self._create_symlink(mynewcpv) @@ -299,7 +299,8 @@ class binarytree(object): if e.errno != errno.EEXIST: raise del e - os.rename(src_path, os.path.join(self.pkgdir, "All", myfile)) + dest_path = os.path.join(self.pkgdir, "All", myfile) + _movefile(src_path, dest_path, mysettings=self.settings) self._create_symlink(cpv) self._pkg_paths[cpv] = os.path.join("All", myfile) @@ -317,7 +318,8 @@ class binarytree(object): if e.errno != errno.EEXIST: raise del e - os.rename(os.path.join(self.pkgdir, "All", myfile), dest_path) + src_path = os.path.join(self.pkgdir, "All", myfile) + _movefile(src_path, dest_path, mysettings=self.settings) self._pkg_paths[cpv] = mypath def populate(self, getbinpkgs=0, getbinpkgsonly=0): @@ -681,7 +683,7 @@ class binarytree(object): pkgindex_lock = lockfile(self._pkgindex_file, wantnewlockfile=1) if filename is not None: - os.rename(filename, self.getname(cpv)) + _movefile(filename, self.getname(cpv), mysettings=self.settings) if self._all_directory and \ self.getname(cpv).split(os.path.sep)[-2] == "All": self._create_symlink(cpv) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index ef6becc72..d27f320d6 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -22,7 +22,7 @@ from portage.versions import pkgsplit, catpkgsplit, catsplit, best, pkgcmp from portage import listdir, dep_expand, config, flatten, key_expand, \ doebuild_environment, doebuild, env_update, \ - abssymlink, movefile, bsd_chflags + abssymlink, movefile, _movefile, bsd_chflags import os, sys, stat, errno, commands, copy, time from itertools import izip @@ -301,7 +301,7 @@ class vardbapi(dbapi): if os.path.exists(newpath): #dest already exists; keep this puppy where it is. continue - os.rename(origpath, newpath) + _movefile(origpath, newpath, mysettings=self.settings) # We need to rename the ebuild now. old_pf = catsplit(mycpv)[1] @@ -1758,7 +1758,7 @@ class dblink(object): # We hold both directory locks. self.dbdir = self.dbpkgdir self.delete() - movefile(self.dbtmpdir, self.dbpkgdir, mysettings=self.settings) + _movefile(self.dbtmpdir, self.dbpkgdir, mysettings=self.settings) contents = self.getcontents() #write out our collection of md5sums -- cgit v1.2.3-1-g7c22