For bug #134620, add a FEATURES=unmerge-orphans option that causes unmerge to remove...
authorZac Medico <zmedico@gentoo.org>
Wed, 13 Jun 2007 07:29:43 +0000 (07:29 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 13 Jun 2007 07:29:43 +0000 (07:29 -0000)
svn path=/main/branches/2.1.2/; revision=6830

cnf/make.globals
man/make.conf.5
pym/portage.py

index b589d9d1314af2a3fbd6fbaedaf767aa4b4e9223..f808d425826a00b83de8633f7cf845d0a6fc7549 100644 (file)
@@ -33,7 +33,7 @@ FETCHCOMMAND="/usr/bin/wget -t 5 -T 60 --passive-ftp -O \${DISTDIR}/\${FILE} \${
 RESUMECOMMAND="/usr/bin/wget -c -t 5 -T 60 --passive-ftp -O \${DISTDIR}/\${FILE} \${URI}"
 
 # Default user options
-FEATURES="sandbox distlocks metadata-transfer"
+FEATURES="sandbox distlocks metadata-transfer unmerge-orphans"
 
 # Default chunksize for binhost comms
 PORTAGE_BINHOST_CHUNKSIZE="3000"
index 5c211f92e447beb5d78d1b8433d84977b637dd03..9fd51c78a67519df4d1783f48e3993730428070e 100644 (file)
@@ -271,6 +271,11 @@ the package compiled properly.  See \fItest\fR in \fBebuild\fR(1)
 and \fIsrc_test()\fR in \fBebuild\fR(5). This feature implies the "test"
 \fBUSE\fR flag.
 .TP
+.B unmerge-orphans
+If a file is not claimed by another package in the same slot and it is not
+protected by \fICONFIG_PROTECT\fR, unmerge it even if the modification time or
+checksum differs from the file that was originally installed.
+.TP
 .B userfetch
 When portage is run as root, drop privileges to portage:portage during the
 fetching of package sources.
index 260ec5f7ee4e341d759ea2b0bee8cf27ed1404a0..4a35a7aa3832a959c5152e3003b6abad1483f990 100644 (file)
@@ -7166,16 +7166,20 @@ class dblink:
                for dblnk in others_in_slot:
                        claimed_paths.update(dblnk.getcontents())
 
+               unmerge_orphans = "unmerge-orphans" in self.settings.features
+
                if pkgfiles:
                        mykeys=pkgfiles.keys()
                        mykeys.sort()
                        mykeys.reverse()
 
                        #process symlinks second-to-last, directories last.
-                       mydirs=[]
-                       modprotect="/lib/modules/"
+                       mydirs = []
+                       modprotect = os.path.join(self.vartree.root, "lib/modules/")
                        for objkey in mykeys:
                                obj = normalize_path(objkey)
+                               file_data = pkgfiles[objkey]
+                               file_type = file_data[0]
                                if obj in claimed_paths:
                                        # A new instance of this package claims the file, so don't
                                        # unmerge it.
@@ -7193,7 +7197,7 @@ class dblink:
                                except (OSError, AttributeError):
                                        pass
                                islink = lstatobj is not None and stat.S_ISLNK(lstatobj.st_mode)
-                               if statobj is None:
+                               if not unmerge_orphans and statobj is None:
                                        if not islink:
                                                #we skip this if we're dealing with a symlink
                                                #because os.stat() will operate on the
@@ -7209,6 +7213,20 @@ class dblink:
                                        writemsg_stdout("--- cfgpro %s %s\n" % (pkgfiles[objkey][0], obj))
                                        continue
 
+                               if unmerge_orphans and \
+                                       lstatobj and not stat.S_ISDIR(lstatobj.st_mode) and \
+                                       not self.isprotected(obj):
+                                       try:
+                                               # Remove permissions to ensure that any hardlinks to
+                                               # suid/sgid files are rendered harmless.
+                                               if statobj:
+                                                       os.chmod(obj, 0)
+                                               os.unlink(obj)
+                                       except EnvironmentError, e:
+                                               pass
+                                       writemsg_stdout("<<<        %s %s\n" % (file_type, obj))
+                                       continue
+
                                lmtime=str(lstatobj[stat.ST_MTIME])
                                if (pkgfiles[objkey][0] not in ("dir","fif","dev")) and (lmtime != pkgfiles[objkey][1]):
                                        writemsg_stdout("--- !mtime %s %s\n" % (pkgfiles[objkey][0], obj))