_unmerge_pkgfiles: improve out-of-prefix unmerging check
authorFabian Groffen <grobian@gentoo.org>
Tue, 30 Nov 2010 18:40:07 +0000 (19:40 +0100)
committerFabian Groffen <grobian@gentoo.org>
Tue, 30 Nov 2010 18:40:07 +0000 (19:40 +0100)
Bug #345633 is likely caused by a corrupted/invalid CONTENTS entry (from
previous buggy Portage releases).  It shows, however, that the unmerge
code wasn't protected well enough against "unmerging" files outside of
the Prefix.  All entries are evaluated now to see if they are within the
Prefix and a warning is issued when they are not, preventing any further
actions to be taken.

pym/portage/dbapi/vartree.py

index 7e10689397f4a149fabdc91b265dd648154f2032..3837f397323107de6170a016e4e426a63a2f9d22 100644 (file)
@@ -1832,6 +1832,7 @@ class dblink(object):
                        unmerge_desc["!mtime"] = _("!mtime")
                        unmerge_desc["!obj"] = _("!obj")
                        unmerge_desc["!sym"] = _("!sym")
+                       unmerge_desc["!prefix"] = _("!prefix")
 
                        real_root = self.settings['ROOT']
                        real_root_len = len(real_root) - 1
@@ -1860,6 +1861,11 @@ class dblink(object):
                                                        os = portage.os
                                                        perf_md5 = portage.checksum.perform_md5
 
+                               # don't try to unmerge the prefix offset itself
+                               if len(obj) <= len(EPREFIX) or not obj.startswith(EPREFIX):
+                                       show_unmerge("---", unmerge_desc["!prefix"], file_type, obj)
+                                       continue
+
                                file_data = pkgfiles[objkey]
                                file_type = file_data[0]
                                statobj = None
@@ -1984,9 +1990,6 @@ class dblink(object):
                        mydirs.reverse()
 
                        for obj in mydirs:
-                               # don't try to unmerge the prefix offset itself
-                               if len(obj) <= len(EPREFIX):
-                                       continue
                                try:
                                        if bsd_chflags:
                                                lstatobj = os.lstat(obj)