summaryrefslogtreecommitdiffstats
path: root/pym/portage/util/_dyn_libs
diff options
context:
space:
mode:
authorDavid James <davidjames@chromium.org>2011-05-05 14:08:27 -0700
committerZac Medico <zmedico@gentoo.org>2011-05-06 18:52:39 -0700
commitf36b9fa38b5268c2a5579db62acec026625f84a9 (patch)
tree43e355af3f6ef42efca4e139ea7265836412bb67 /pym/portage/util/_dyn_libs
parent2fc0237f7ecda61abebd46bb7dc9f173bbed8868 (diff)
downloadportage-f36b9fa38b5268c2a5579db62acec026625f84a9.tar.gz
portage-f36b9fa38b5268c2a5579db62acec026625f84a9.tar.bz2
portage-f36b9fa38b5268c2a5579db62acec026625f84a9.zip
Cleanup preserved lib locking in portage.
This change makes preserved lib modification atomic, and prepares us for narrowing the scope of the merge lock. BUG=chromium-os:14983 TEST=Ran test suite and some example emerges. Change-Id: I39abb6a5ec72be3274e508ef807ac1d9e69db1a8 Review URL: http://gerrit.chromium.org/gerrit/417
Diffstat (limited to 'pym/portage/util/_dyn_libs')
-rw-r--r--pym/portage/util/_dyn_libs/PreservedLibsRegistry.py32
1 files changed, 19 insertions, 13 deletions
diff --git a/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py b/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py
index 0d0b57d21..f3cbb3390 100644
--- a/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py
+++ b/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py
@@ -18,23 +18,29 @@ from portage.localization import _
from portage.util import atomic_ofstream
from portage.util import writemsg_level
from portage.versions import cpv_getkey
+from portage.locks import lockfile, unlockfile
class PreservedLibsRegistry(object):
""" This class handles the tracking of preserved library objects """
- def __init__(self, root, filename, autocommit=True):
+ def __init__(self, root, filename):
"""
@param root: root used to check existence of paths in pruneNonExisting
@type root: String
@param filename: absolute path for saving the preserved libs records
@type filename: String
- @param autocommit: determines if the file is written after every update
- @type autocommit: Boolean
"""
self._root = root
self._filename = filename
- self._autocommit = autocommit
- self.load()
- self.pruneNonExisting()
+ self._data = None
+ self._lock = None
+
+ def lock(self):
+ """Grab an exclusive lock on the preserved libs registry."""
+ self._lock = lockfile(self._filename)
+
+ def unlock(self):
+ """Release our exclusive lock on the preserved libs registry."""
+ unlockfile(self._lock)
def load(self):
""" Reload the registry data from file """
@@ -56,10 +62,10 @@ class PreservedLibsRegistry(object):
if self._data is None:
self._data = {}
self._data_orig = self._data.copy()
+ self.pruneNonExisting()
+
def store(self):
- """ Store the registry data to file. No need to call this if autocommit
- was enabled.
- """
+ """ Store the registry data to file """
if os.environ.get("SANDBOX_ON") == "1" or \
self._data == self._data_orig:
return
@@ -94,8 +100,6 @@ class PreservedLibsRegistry(object):
del self._data[cps]
elif len(paths) > 0:
self._data[cps] = (cpv, counter, paths)
- if self._autocommit:
- self.store()
def unregister(self, cpv, slot, counter):
""" Remove a previous registration of preserved objects for the given package.
@@ -119,11 +123,11 @@ class PreservedLibsRegistry(object):
self._data[cps] = (cpv, counter, paths)
else:
del self._data[cps]
- if self._autocommit:
- self.store()
def hasEntries(self):
""" Check if this registry contains any records. """
+ if self._data is None:
+ self.load()
return len(self._data) > 0
def getPreservedLibs(self):
@@ -131,6 +135,8 @@ class PreservedLibsRegistry(object):
@returns mapping of package instances to preserved objects
@rtype Dict cpv->list-of-paths
"""
+ if self._data is None:
+ self.load()
rValue = {}
for cps in self._data:
rValue[self._data[cps][0]] = self._data[cps][2]