dblink.getcontents(): generate parent directories
authorZac Medico <zmedico@gentoo.org>
Wed, 2 Mar 2011 18:51:41 +0000 (10:51 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 2 Mar 2011 18:51:41 +0000 (10:51 -0800)
We can't necessarily assume that they are explicitly listed in
CONTENTS, and they are crucial for callers such as dblink.isowner().

pym/portage/dbapi/vartree.py

index 04e66ab76f1e2f1a3d488808ea76e5a6cc9ca536..cd8b1c1c12208b37e10f5142dea0c13829362063 100644 (file)
@@ -1404,6 +1404,9 @@ class dblink(object):
                myroot = self.settings['ROOT']
                if myroot == os.path.sep:
                        myroot = None
+               # used to generate parent dir entries
+               dir_entry = (_unicode_decode("dir"),)
+               eroot_split_len = len(self.settings["EROOT"].split(os.sep)) - 1
                pos = 0
                errors = []
                for pos, line in enumerate(mylines):
@@ -1448,6 +1451,19 @@ class dblink(object):
                        if myroot is not None:
                                path = os.path.join(myroot, path.lstrip(os.path.sep))
 
+                       # Implicitly add parent directories, since we can't necessarily
+                       # assume that they are explicitly listed in CONTENTS, and it's
+                       # useful for callers if they can rely on parent directory entries
+                       # being generated here (crucial for things like dblink.isowner()).
+                       path_split = path.split(os.sep)
+                       path_split.pop()
+                       while len(path_split) > eroot_split_len:
+                               parent = os.sep.join(path_split)
+                               if parent in pkgfiles:
+                                       break
+                               pkgfiles[parent] = dir_entry
+                               path_split.pop()
+
                        pkgfiles[path] = data
 
                if errors: