Always check if vardbapi._linkmap and vardbapi._plib_registry are
authorZac Medico <zmedico@gentoo.org>
Mon, 30 Aug 2010 06:49:32 +0000 (23:49 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 30 Aug 2010 06:49:32 +0000 (23:49 -0700)
None before trying to use them. This will be useful in the upcoming
2.1.9 branch which will not have preserve-libs support but will
still have the code in private and disabled form.

pym/_emerge/actions.py
pym/_emerge/clear_caches.py
pym/_emerge/main.py
pym/portage/dbapi/vartree.py
pym/portage/sets/libs.py

index a2cff59574b4befdc8bc1185ac5c9c70aba97266..99b2a469ea1b5e90d8364cbbb3c0c664450884d8 100644 (file)
@@ -447,7 +447,13 @@ def action_build(settings, trees, mtimedb,
                                portage.writemsg_stdout(colorize("WARN", "WARNING:")
                                        + " AUTOCLEAN is disabled.  This can cause serious"
                                        + " problems due to overlapping packages.\n")
-                       trees[settings["ROOT"]]["vartree"].dbapi._plib_registry.pruneNonExisting()
+                       plib_registry = \
+                               trees[settings["ROOT"]]["vartree"].dbapi._plib_registry
+                       if plib_registry is None:
+                               # preserve-libs is entirely disabled
+                               pass
+                       else:
+                               plib_registry.pruneNonExisting()
 
                return retval
 
@@ -875,7 +881,9 @@ def calc_depclean(settings, trees, ldpath_mtimes,
        cleanlist = create_cleanlist()
        clean_set = set(cleanlist)
 
-       if cleanlist and myopts.get('--depclean-lib-check') != 'n':
+       if cleanlist and \
+               real_vardb._linkmap is not None and \
+               myopts.get('--depclean-lib-check') != 'n':
 
                # Check if any of these package are the sole providers of libraries
                # with consumers that have not been selected for removal. If so, these
index a0e945255ef5ba5f9faa0f2a1161109fd8a41d1b..7b7c5eced6a9c5733dd6e5421723804885978e3a 100644 (file)
@@ -10,6 +10,10 @@ def clear_caches(trees):
                d["porttree"].dbapi._aux_cache.clear()
                d["bintree"].dbapi._aux_cache.clear()
                d["bintree"].dbapi._clear_cache()
-               d["vartree"].dbapi._linkmap._clear_cache()
+               if d["vartree"].dbapi._linkmap is None:
+                       # preserve-libs is entirely disabled
+                       pass
+               else:
+                       d["vartree"].dbapi._linkmap._clear_cache()
        dircache.clear()
        gc.collect()
index 4b77f3b1f326f20552f91692807244436d05cadf..3bd72226fe30bda8f64d3ae5e8038c5d4bb45319 100644 (file)
@@ -211,6 +211,11 @@ def chk_updated_info_files(root, infodirs, prev_mtimes, retval):
 def display_preserved_libs(vardbapi, myopts):
        MAX_DISPLAY = 3
 
+       if vardbapi._linkmap is None or \
+               vardbapi._plib_registry is None:
+               # preserve-libs is entirely disabled
+               return
+
        # Ensure the registry is consistent with existing files.
        vardbapi._plib_registry.pruneNonExisting()
 
index 72685b5ada7367b227b419b47a533e1a30e4a15b..bda2d5145e2151c0eedbfc6a0e1243b396f20953 100644 (file)
@@ -1526,8 +1526,12 @@ class dblink(object):
 
                        # Remove the registration of preserved libs for this pkg instance
                        plib_registry = self.vartree.dbapi._plib_registry
-                       plib_registry.unregister(self.mycpv, self.settings["SLOT"],
-                               self.vartree.dbapi.cpv_counter(self.mycpv))
+                       if plib_registry is None:
+                               # preserve-libs is entirely disabled
+                               pass
+                       else:
+                               plib_registry.unregister(self.mycpv, self.settings["SLOT"],
+                                       self.vartree.dbapi.cpv_counter(self.mycpv))
 
                        if myebuildpath:
                                ebuild_phase = "postrm"
@@ -1567,7 +1571,11 @@ class dblink(object):
                        else:
                                # Prune any preserved libs that may have
                                # been unmerged with this package.
-                               self.vartree.dbapi._plib_registry.pruneNonExisting()
+                               if plib_registry is None:
+                                       # preserve-libs is entirely disabled
+                                       pass
+                               else:
+                                       plib_registry.pruneNonExisting()
 
                finally:
                        self.vartree.dbapi._bump_mtime(self.mycpv)
@@ -2165,6 +2173,8 @@ class dblink(object):
                and the preserve-libs registry is empty.
                """
                if self._linkmap_broken or \
+                       self.vartree.dbapi._linkmap is None or \
+                       self.vartree.dbapi._plib_registry is None or \
                        ("preserve-libs" not in self.settings.features and \
                        not self.vartree.dbapi._plib_registry.hasEntries()):
                        return
@@ -2181,9 +2191,11 @@ class dblink(object):
                Get set of relative paths for libraries to be preserved. The file
                paths are selected from self._installed_instance.getcontents().
                """
-               if self._linkmap_broken or not \
-                       (self._installed_instance is not None and \
-                       "preserve-libs" in self.settings.features):
+               if self._linkmap_broken or \
+                       self.vartree.dbapi._linkmap is None or \
+                       self.vartree.dbapi._plib_registry is None or \
+                       self._installed_instance is None or \
+                       "preserve-libs" not in self.settings.features:
                        return None
 
                os = _os_merge
@@ -2345,6 +2357,8 @@ class dblink(object):
                """
 
                if self._linkmap_broken or \
+                       self.vartree.dbapi._linkmap is None or \
+                       self.vartree.dbapi._plib_registry is None or \
                        not self.vartree.dbapi._plib_registry.hasEntries():
                        return {}
 
@@ -2500,14 +2514,21 @@ class dblink(object):
 
                        # For collisions with preserved libraries, the current package
                        # will assume ownership and the libraries will be unregistered.
-                       plib_dict = self.vartree.dbapi._plib_registry.getPreservedLibs()
-                       plib_cpv_map = {}
-                       plib_paths = set()
-                       for cpv, paths in plib_dict.items():
-                               plib_paths.update(paths)
-                               for f in paths:
-                                       plib_cpv_map[f] = cpv
-                       plib_inodes = self._lstat_inode_map(plib_paths)
+                       if self.vartree.dbapi._plib_registry is None:
+                               # preserve-libs is entirely disabled
+                               plib_cpv_map = None
+                               plib_paths = None
+                               plib_inodes = {}
+                       else:
+                               plib_dict = self.vartree.dbapi._plib_registry.getPreservedLibs()
+                               plib_cpv_map = {}
+                               plib_paths = set()
+                               for cpv, paths in plib_dict.items():
+                                       plib_paths.update(paths)
+                                       for f in paths:
+                                               plib_cpv_map[f] = cpv
+                               plib_inodes = self._lstat_inode_map(plib_paths)
+
                        plib_collisions = {}
 
                        showMessage = self._display_merge
@@ -3239,13 +3260,17 @@ class dblink(object):
                self._clear_contents_cache()
 
                linkmap = self.vartree.dbapi._linkmap
-               self._linkmap_rebuild(include_file=os.path.join(inforoot,
-                       linkmap._needed_aux_key))
+               if linkmap is None:
+                       # preserve-libs is entirely disabled
+                       preserve_paths = None
+               else:
+                       self._linkmap_rebuild(include_file=os.path.join(inforoot,
+                               linkmap._needed_aux_key))
 
-               # Preserve old libs if they are still in use
-               preserve_paths = self._find_libs_to_preserve()
-               if preserve_paths:
-                       self._add_preserve_libs_to_contents(preserve_paths)
+                       # Preserve old libs if they are still in use
+                       preserve_paths = self._find_libs_to_preserve()
+                       if preserve_paths:
+                               self._add_preserve_libs_to_contents(preserve_paths)
 
                # If portage is reinstalling itself, remove the old
                # version now since we want to use the temporary
@@ -3303,7 +3328,8 @@ class dblink(object):
                _movefile(self.dbtmpdir, self.dbpkgdir, mysettings=self.settings)
 
                # keep track of the libs we preserved
-               if preserve_paths:
+               if self.vartree.dbapi._plib_registry is not None and \
+                       preserve_paths:
                        self.vartree.dbapi._plib_registry.register(self.mycpv,
                                slot, counter, sorted(preserve_paths))
 
@@ -3320,20 +3346,24 @@ class dblink(object):
                # Unregister any preserved libs that this package has overwritten
                # and update the contents of the packages that owned them.
                plib_registry = self.vartree.dbapi._plib_registry
-               plib_dict = plib_registry.getPreservedLibs()
-               for cpv, paths in plib_collisions.items():
-                       if cpv not in plib_dict:
-                               continue
-                       if cpv == self.mycpv:
-                               continue
-                       try:
-                               slot, counter = self.vartree.dbapi.aux_get(
-                                       cpv, ["SLOT", "COUNTER"])
-                       except KeyError:
-                               continue
-                       remaining = [f for f in plib_dict[cpv] if f not in paths]
-                       plib_registry.register(cpv, slot, counter, remaining)
-                       self.vartree.dbapi.removeFromContents(cpv, paths)
+               if plib_registry is None:
+                       # preserve-libs is entirely disabled
+                       pass
+               else:
+                       plib_dict = plib_registry.getPreservedLibs()
+                       for cpv, paths in plib_collisions.items():
+                               if cpv not in plib_dict:
+                                       continue
+                               if cpv == self.mycpv:
+                                       continue
+                               try:
+                                       slot, counter = self.vartree.dbapi.aux_get(
+                                               cpv, ["SLOT", "COUNTER"])
+                               except KeyError:
+                                       continue
+                               remaining = [f for f in plib_dict[cpv] if f not in paths]
+                               plib_registry.register(cpv, slot, counter, remaining)
+                               self.vartree.dbapi.removeFromContents(cpv, paths)
 
                self.vartree.dbapi._add(self)
                contents = self.getcontents()
@@ -3773,8 +3803,14 @@ class dblink(object):
                self.lockdb()
                self.vartree.dbapi._bump_mtime(self.mycpv)
                try:
-                       self.vartree.dbapi._plib_registry.load()
-                       self.vartree.dbapi._plib_registry.pruneNonExisting()
+                       plib_registry = self.vartree.dbapi._plib_registry
+                       if plib_registry is None:
+                               # preserve-libs is entirely disabled
+                               pass
+                       else:
+                               plib_registry.load()
+                               plib_registry.pruneNonExisting()
+
                        retval = self.treewalk(mergeroot, myroot, inforoot, myebuild,
                                cleanup=cleanup, mydbapi=mydbapi, prev_mtimes=prev_mtimes)
 
@@ -3820,7 +3856,11 @@ class dblink(object):
 
                finally:
                        self.settings.pop('REPLACING_VERSIONS', None)
-                       self.vartree.dbapi._linkmap._clear_cache()
+                       if self.vartree.dbapi._linkmap is None:
+                               # preserve-libs is entirely disabled
+                               pass
+                       else:
+                               self.vartree.dbapi._linkmap._clear_cache()
                        self.unlockdb()
                        self.vartree.dbapi._bump_mtime(self.mycpv)
                return retval
@@ -3919,15 +3959,24 @@ def unmerge(cat, pkg, myroot=None, settings=None,
        try:
                mylink.lockdb()
                if mylink.exists():
-                       vartree.dbapi._plib_registry.load()
-                       vartree.dbapi._plib_registry.pruneNonExisting()
+                       plib_registry = vartree.dbapi._plib_registry
+                       if plib_registry is None:
+                               # preserve-libs is entirely disabled
+                               pass
+                       else:
+                               plib_registry.load()
+                               plib_registry.pruneNonExisting()
                        retval = mylink.unmerge(ldpath_mtimes=ldpath_mtimes)
                        if retval == os.EX_OK:
                                mylink.delete()
                        return retval
                return os.EX_OK
        finally:
-               vartree.dbapi._linkmap._clear_cache()
+               if vartree.dbapi._linkmap is None:
+                       # preserve-libs is entirely disabled
+                       pass
+               else:
+                       vartree.dbapi._linkmap._clear_cache()
                mylink.unlockdb()
 
 def write_contents(contents, root, f):
index b20acebf035ec47a690107e2e59c818765718566..74c16a12974f2a287d7ab0b1fa1fc05e3f57a585 100644 (file)
@@ -60,6 +60,9 @@ class LibraryFileConsumerSet(LibraryConsumerSet):
 class PreservedLibraryConsumerSet(LibraryConsumerSet):
        def load(self):
                reg = self.dbapi._plib_registry
+               if reg is None:
+                       # preserve-libs is entirely disabled
+                       return
                consumers = set()
                if reg:
                        plib_dict = reg.getPreservedLibs()