summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-05-07 10:25:20 -0700
committerZac Medico <zmedico@gentoo.org>2011-05-07 10:25:20 -0700
commit48e1b835df5fefe49e2227e37c007d87fade1c55 (patch)
tree90f4ba6a1a085b9eb4ab35ca0563cfcccc861324
parent547d22391e7162fe79a793d7662b3d6d60327796 (diff)
downloadportage-48e1b835df5fefe49e2227e37c007d87fade1c55.tar.gz
portage-48e1b835df5fefe49e2227e37c007d87fade1c55.tar.bz2
portage-48e1b835df5fefe49e2227e37c007d87fade1c55.zip
PreserveLibsRegistry: add lock/unlock assertions
Also, add comments to store() about unobvious interaction with locking due to atomic replacement of the inode.
-rw-r--r--pym/portage/util/_dyn_libs/PreservedLibsRegistry.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py b/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py
index f3cbb3390..3fb812048 100644
--- a/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py
+++ b/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py
@@ -36,11 +36,16 @@ class PreservedLibsRegistry(object):
def lock(self):
"""Grab an exclusive lock on the preserved libs registry."""
+ if self._lock is not None:
+ raise AssertionError("already locked")
self._lock = lockfile(self._filename)
def unlock(self):
"""Release our exclusive lock on the preserved libs registry."""
+ if self._lock is None:
+ raise AssertionError("not locked")
unlockfile(self._lock)
+ self._lock = None
def load(self):
""" Reload the registry data from file """
@@ -65,7 +70,13 @@ class PreservedLibsRegistry(object):
self.pruneNonExisting()
def store(self):
- """ Store the registry data to file """
+ """
+ Store the registry data to the file. The existing inode will be
+ replaced atomically, so if that inode is currently being used
+ for a lock then that lock will be rendered useless. Therefore,
+ it is important not to call this method until the current lock
+ is ready to be immediately released.
+ """
if os.environ.get("SANDBOX_ON") == "1" or \
self._data == self._data_orig:
return