Index: portage-2.1.2_pre3/pym/portage.py =================================================================== --- portage-2.1.2_pre3.orig/pym/portage.py +++ portage-2.1.2_pre3/pym/portage.py @@ -23,6 +23,12 @@ try: except ImportError: import pickle as cPickle + # Move this at the start of the merge codepath to avoid useless imports + bsdflags = os.uname()[0] in ["FreeBSD"] + + if bsdflags: + import freebsd + import stat import commands from time import sleep @@ -42,13 +48,6 @@ except ImportError, e: raise try: - # XXX: This should get renamed to bsd_chflags, I think. - import chflags - bsd_chflags = chflags -except ImportError: - bsd_chflags = None - -try: from cache.cache_errors import CacheError import cvstree import xpak @@ -3270,23 +3269,12 @@ def movefile(src,dest,newmtime=None,ssta dstat=os.lstat(os.path.dirname(dest)) destexists=0 - if bsd_chflags: - # Check that we can actually unset schg etc flags... - # Clear the flags on source and destination; we'll reinstate them after merging + if bsdflags: if destexists and dstat.st_flags != 0: - if bsd_chflags.lchflags(dest, 0) < 0: - writemsg("!!! Couldn't clear flags on file being merged: \n ", - noiselevel=-1) - # We might have an immutable flag on the parent dir; save and clear. - pflags=bsd_chflags.lgetflags(os.path.dirname(dest)) + freebsd.lchflags(dest, 0) + pflags = os.stat(os.path.dirname(dest)).st_flags if pflags != 0: - bsd_chflags.lchflags(os.path.dirname(dest), 0) - - if (destexists and bsd_chflags.lhasproblems(dest)>0) or bsd_chflags.lhasproblems(os.path.dirname(dest))>0: - # This is bad: we can't merge the file with these flags set. - writemsg("!!! Can't merge file "+dest+" because of flags set\n", - noiselevel=-1) - return None + freebsd.lchflags(os.path.dirname(dest), 0) if destexists: if stat.S_ISLNK(dstat[stat.ST_MODE]): @@ -3388,12 +3376,10 @@ def movefile(src,dest,newmtime=None,ssta os.utime(dest, (sstat[stat.ST_ATIME], sstat[stat.ST_MTIME])) newmtime=sstat[stat.ST_MTIME] - if bsd_chflags: + if bsdflags: # Restore the flags we saved before moving - if pflags and bsd_chflags.lchflags(os.path.dirname(dest), pflags) < 0: - writemsg("!!! Couldn't restore flags ("+str(sflags)+") on " + dest+":\n", - noiselevel=-1) - return None + if pflags: + freebsd.lchflags(os.path.dirname(dest), pflags) return newmtime @@ -6649,12 +6635,11 @@ class dblink: if mydmode!=None: # destination exists - if bsd_chflags: + if bsdflags: # Save then clear flags on dest. - dflags=bsd_chflags.lgetflags(mydest) - if dflags != 0 and bsd_chflags.lchflags(mydest, 0) < 0: - writemsg("!!! Couldn't clear flags on '"+mydest+"'.\n", - noiselevel=-1) + dflags = os.lstat(mydest).st_flags + if dflags != 0: + freebsd.lchflags(mydest, 0) if not os.access(mydest, os.W_OK): pkgstuff = pkgsplit(self.pkg) @@ -6668,8 +6653,8 @@ class dblink: if stat.S_ISLNK(mydmode) or stat.S_ISDIR(mydmode): # a symlink to an existing directory will work for us; keep it: writemsg_stdout("--- %s/\n" % mydest) - if bsd_chflags: - bsd_chflags.lchflags(mydest, dflags) + if bsdflags: + freebsd.lchflags(mydest, dflags) else: # a non-directory and non-symlink-to-directory. Won't work for us. Move out of the way. if movefile(mydest,mydest+".backup", mysettings=self.settings) is None: @@ -6681,8 +6666,8 @@ class dblink: selinux.secure_mkdir(mydest,sid) else: os.mkdir(mydest) - if bsd_chflags: - bsd_chflags.lchflags(mydest, dflags) + if bsdflags: + freebsd.lchflags(mydest, dflags) os.chmod(mydest,mystat[0]) os.chown(mydest,mystat[4],mystat[5]) writemsg_stdout(">>> %s/\n" % mydest)