From f9895ac7a04ee31af370151f238409cae4ac1a01 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 1 Mar 2011 12:07:53 -0800 Subject: [PATCH] unmerge: implicitly unmerge parent directories We can't necessarily assume that they are explicitly listed in CONTENTS. --- pym/portage/dbapi/vartree.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index b8881c817..a7a7d4063 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -1784,7 +1784,7 @@ class dblink(object): mykeys.reverse() #process symlinks second-to-last, directories last. - mydirs = [] + mydirs = set() ignored_unlink_errnos = ( errno.EBUSY, errno.ENOENT, errno.ENOTDIR, errno.EISDIR) @@ -1846,6 +1846,7 @@ class dblink(object): real_root = self.settings['ROOT'] real_root_len = len(real_root) - 1 + eroot_split_len = len(self.settings["EROOT"].split(os.sep)) - 1 for i, objkey in enumerate(mykeys): @@ -1871,6 +1872,18 @@ class dblink(object): os = portage.os perf_md5 = portage.checksum.perform_md5 + # Try to unmerge parent directories of everything + # listed in CONTENTS, since we can't necessarily + # assume that directories are listed in CONTENTS. + obj_split = obj.split(os.sep) + obj_split.pop() + while len(obj_split) > eroot_split_len: + parent = os.sep.join(obj_split) + if parent in mydirs: + break + mydirs.add(parent) + obj_split.pop() + file_data = pkgfiles[objkey] file_type = file_data[0] statobj = None @@ -1939,7 +1952,7 @@ class dblink(object): if lstatobj is None or not stat.S_ISDIR(lstatobj.st_mode): show_unmerge("---", unmerge_desc["!dir"], file_type, obj) continue - mydirs.append(obj) + mydirs.add(obj) elif pkgfiles[objkey][0] == "sym": if not islink: show_unmerge("---", unmerge_desc["!sym"], file_type, obj) @@ -1991,7 +2004,7 @@ class dblink(object): elif pkgfiles[objkey][0] == "dev": show_unmerge("---", "", file_type, obj) - mydirs.sort() + mydirs = sorted(mydirs) mydirs.reverse() for obj in mydirs: -- 2.26.2