_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>
Thu, 26 May 2011 02:48:43 +0000 (19:48 -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 4e19b1065a87f03c84963da2a181af3b0f6d724e..8de794573a445c8e33dc6744944224014174d768 100644 (file)
@@ -2309,7 +2309,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
@@ -2464,6 +2464,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()
@@ -2474,7 +2475,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
@@ -2482,7 +2483,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 3305aca49f2d15648c4394abb3d24a740da9091e..2c40a346e3a946b55dbe297cbf26aac79761a6e1 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):