Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: pym/portage/dbapi/vartree.py

Issue 6714030: Cleanup preserved lib locking in portage. (Closed)
Patch Set: Rebase Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pym/_emerge/main.py ('k') | pym/portage/util/_dyn_libs/PreservedLibsRegistry.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pym/portage/dbapi/vartree.py
diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
index 08263d6d3bd03267f7f1cb058300319e8777acce..891c516a0825bfba4bc6922eefff822267707194 100644
--- a/pym/portage/dbapi/vartree.py
+++ b/pym/portage/dbapi/vartree.py
@@ -148,13 +148,9 @@ class vardbapi(dbapi):
self._plib_registry = None
if _ENABLE_PRESERVE_LIBS:
- try:
- self._plib_registry = PreservedLibsRegistry(self.root,
- os.path.join(self._eroot, PRIVATE_PATH,
- "preserved_libs_registry"))
- except PermissionDenied:
- # apparently this user isn't allowed to access PRIVATE_PATH
- pass
+ self._plib_registry = PreservedLibsRegistry(self.root,
+ os.path.join(self._eroot, PRIVATE_PATH,
+ "preserved_libs_registry"))
self._linkmap = None
if _ENABLE_DYN_LINK_MAP:
@@ -1437,6 +1433,41 @@ class dblink(object):
self.contentscache = pkgfiles
return pkgfiles
+ def _prune_plib_registry(self, others_in_slot=[]):
+ # remove preserved libraries that don't have any consumers left
+ plib_registry = self.vartree.dbapi._plib_registry
+ if plib_registry:
+ plib_registry.lock()
+ try:
+ plib_registry.load()
+
+ # Skip this if another package in the same slot has just been
+ # merged on top of this package, since the other package has
+ # already called LinkageMap.rebuild() and passed it's NEEDED file
+ # in as an argument.
+ if not others_in_slot:
+ self._linkmap_rebuild(exclude_pkgs=(self.mycpv,))
+
+ cpv_lib_map = self._find_unused_preserved_libs()
+ if cpv_lib_map:
+ self._remove_preserved_libs(cpv_lib_map)
+ for cpv, removed in cpv_lib_map.items():
+ if not self.vartree.dbapi.cpv_exists(cpv):
+ for dblnk in others_in_slot:
+ if dblnk.mycpv == cpv:
+ # This one just got merged so it doesn't
+ # register with cpv_exists() yet.
+ self.vartree.dbapi.removeFromContents(
+ dblnk, removed)
+ break
+ continue
+ self.vartree.dbapi.removeFromContents(cpv, removed)
+ plib_registry.unregister(self.mycpv, self.settings["SLOT"],
+ self.vartree.dbapi.cpv_counter(self.mycpv))
+ plib_registry.store()
+ finally:
+ plib_registry.unlock()
+
def unmerge(self, pkgfiles=None, trimworld=None, cleanup=True,
ldpath_mtimes=None, others_in_slot=None):
"""
@@ -1574,15 +1605,6 @@ class dblink(object):
self._unmerge_pkgfiles(pkgfiles, others_in_slot)
self._clear_contents_cache()
- # Remove the registration of preserved libs for this pkg instance
- plib_registry = self.vartree.dbapi._plib_registry
- 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"
phase = EbuildPhase(background=background,
@@ -1597,37 +1619,7 @@ class dblink(object):
showMessage(_("!!! FAILED postrm: %s\n") % retval,
level=logging.ERROR, noiselevel=-1)
- # Skip this if another package in the same slot has just been
- # merged on top of this package, since the other package has
- # already called LinkageMap.rebuild() and passed it's NEEDED file
- # in as an argument.
- if not others_in_slot:
- self._linkmap_rebuild(exclude_pkgs=(self.mycpv,))
-
- # remove preserved libraries that don't have any consumers left
- cpv_lib_map = self._find_unused_preserved_libs()
- if cpv_lib_map:
- self._remove_preserved_libs(cpv_lib_map)
- for cpv, removed in cpv_lib_map.items():
- if not self.vartree.dbapi.cpv_exists(cpv):
- for dblnk in others_in_slot:
- if dblnk.mycpv == cpv:
- # This one just got merged so it doesn't
- # register with cpv_exists() yet.
- self.vartree.dbapi.removeFromContents(
- dblnk, removed)
- break
- continue
- self.vartree.dbapi.removeFromContents(cpv, removed)
- else:
- # Prune any preserved libs that may have
- # been unmerged with this package.
- if plib_registry is None:
- # preserve-libs is entirely disabled
- pass
- else:
- plib_registry.pruneNonExisting()
-
+ self._prune_plib_registry(others_in_slot)
finally:
self.vartree.dbapi._bump_mtime(self.mycpv)
if builddir_lock:
@@ -3335,12 +3327,6 @@ class dblink(object):
self.delete()
_movefile(self.dbtmpdir, self.dbpkgdir, mysettings=self.settings)
- # keep track of the libs we preserved
- 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))
-
# Check for file collisions with blocking packages
# and remove any colliding files from their CONTENTS
# since they now belong to this package.
@@ -3351,27 +3337,37 @@ class dblink(object):
self.vartree.dbapi.removeFromContents(blocker, iter(contents),
relative_paths=False)
- # 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
- 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)
+ if plib_registry:
+ plib_registry.lock()
+ try:
+ plib_registry.load()
+
+ if preserve_paths:
+ # keep track of the libs we preserved
+ plib_registry.register(self.mycpv, slot, counter,
+ sorted(preserve_paths))
+
+ # Unregister any preserved libs that this package has overwritten
+ # and update the contents of the packages that owned them.
+ 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)
+
+ plib_registry.store()
+ finally:
+ plib_registry.unlock()
self.vartree.dbapi._add(self)
contents = self.getcontents()
@@ -3410,14 +3406,7 @@ class dblink(object):
# For gcc upgrades, preserved libs have to be removed after the
# the library path has been updated.
- self._linkmap_rebuild()
- cpv_lib_map = self._find_unused_preserved_libs()
- if cpv_lib_map:
- self._remove_preserved_libs(cpv_lib_map)
- for cpv, removed in cpv_lib_map.items():
- if not self.vartree.dbapi.cpv_exists(cpv):
- continue
- self.vartree.dbapi.removeFromContents(cpv, removed)
+ self._prune_plib_registry()
return os.EX_OK
@@ -3839,14 +3828,6 @@ class dblink(object):
self.lockdb()
self.vartree.dbapi._bump_mtime(self.mycpv)
try:
- 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)
@@ -4001,13 +3982,6 @@ def unmerge(cat, pkg, myroot=None, settings=None,
try:
mylink.lockdb()
if mylink.exists():
- 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()
« no previous file with comments | « pym/_emerge/main.py ('k') | pym/portage/util/_dyn_libs/PreservedLibsRegistry.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698