_LibGraphNode: re-use the _key attribute
authorZac Medico <zmedico@gentoo.org>
Sun, 15 May 2011 01:56:39 +0000 (18:56 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 15 May 2011 01:56:39 +0000 (18:56 -0700)
This allows us to avoid repeating any previous stat calls, which helps
to avoid potential race conditions due to inconsistent stat results
when the file system is being modified concurrently.

pym/portage/dbapi/vartree.py
pym/portage/util/_dyn_libs/LinkageMapELF.py

index 802253afc173a33f67102d6a63c493c3337190ea..d1905663df019d93466afbf2e655620014120478 100644 (file)
@@ -2344,7 +2344,7 @@ class dblink(object):
                def path_to_node(path):
                        node = path_node_map.get(path)
                        if node is None:
-                               node = LinkageMap._LibGraphNode(path, root)
+                               node = LinkageMap._LibGraphNode(linkmap._obj_key(path))
                                alt_path_node = lib_graph.get(node)
                                if alt_path_node is not None:
                                        node = alt_path_node
@@ -2499,6 +2499,7 @@ class dblink(object):
                # Since preserved libraries can be consumers of other preserved
                # libraries, use a graph to track consumer relationships.
                plib_dict = self.vartree.dbapi._plib_registry.getPreservedLibs()
+               linkmap = self.vartree.dbapi._linkmap
                lib_graph = digraph()
                preserved_nodes = set()
                preserved_paths = set()
@@ -2509,7 +2510,7 @@ class dblink(object):
                def path_to_node(path):
                        node = path_node_map.get(path)
                        if node is None:
-                               node = LinkageMap._LibGraphNode(path, root)
+                               node = LinkageMap._LibGraphNode(linkmap._obj_key(path))
                                alt_path_node = lib_graph.get(node)
                                if alt_path_node is not None:
                                        node = alt_path_node
@@ -2517,7 +2518,6 @@ class dblink(object):
                                path_node_map[path] = node
                        return node
 
-               linkmap = self.vartree.dbapi._linkmap
                for cpv, plibs in plib_dict.items():
                        for f in plibs:
                                path_cpv_map[f] = cpv
index fe86a7a896821c8f1738069b61985a8ac4b5ea09..fef75b62c55557a3de5535757978b622ac4ad7a4 100644 (file)
@@ -60,7 +60,7 @@ class LinkageMapELF(object):
 
                """Helper class used as _obj_properties keys for objects."""
 
-               __slots__ = ("__weakref__", "_key")
+               __slots__ = ("_key",)
 
                def __init__(self, obj, root):
                        """
@@ -135,8 +135,15 @@ class LinkageMapELF(object):
        class _LibGraphNode(_ObjectKey):
                __slots__ = ("alt_paths",)
 
-               def __init__(self, obj, root):
-                       LinkageMapELF._ObjectKey.__init__(self, obj, root)
+               def __init__(self, key):
+                       """
+                       Create a _LibGraphNode from an existing _ObjectKey.
+                       This re-uses the _key attribute in order to avoid repeating
+                       any previous stat calls, which helps to avoid potential race
+                       conditions due to inconsistent stat results when the
+                       file system is being modified concurrently.
+                       """
+                       self._key = key._key
                        self.alt_paths = set()
 
                def __str__(self):