removeFromContents: avoid KeyError, bug #454400
authorZac Medico <zmedico@gentoo.org>
Mon, 28 Jan 2013 21:18:00 +0000 (13:18 -0800)
committerZac Medico <zmedico@gentoo.org>
Mon, 28 Jan 2013 21:19:10 +0000 (13:19 -0800)
It's possible for two different paths to refer to the same
contents_key, due to directory symlinks. This could happen if a
directory was changed to a symlink after a package was merged, either
by the user or by a pkg_* phase from some random ebuild.

pym/portage/dbapi/vartree.py

index bbcf61c9f970c055c5f7c696378ee465da9cae97..a2fbf86df8bd51651e6173c8f49cbb1df67465f4 100644 (file)
@@ -1002,7 +1002,11 @@ class vardbapi(dbapi):
                                relative_filename = filename[root_len:]
                        contents_key = pkg._match_contents(relative_filename)
                        if contents_key:
-                               del new_contents[contents_key]
+                               # It's possible for two different paths to refer to the same
+                               # contents_key, due to directory symlinks. Therefore, pass a
+                               # default value to pop, in order to avoid a KeyError which
+                               # could otherwise be triggered (see bug #454400).
+                               new_contents.pop(contents_key, None)
                                removed += 1
 
                if removed: