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-08 11:42:35 -0700
commiteaa0691df6216347060d267e0285674a1b31ac2f (patch)
treee85993e9c83807261b498f7d0e19abaa0307e5d4
parent7a2cef7d74ec6fe48b88803e1300cc77c687e922 (diff)
downloadportage-eaa0691df6216347060d267e0285674a1b31ac2f.tar.gz
portage-eaa0691df6216347060d267e0285674a1b31ac2f.tar.bz2
portage-eaa0691df6216347060d267e0285674a1b31ac2f.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