diff options
author | Matt Turner <mattst88@gentoo.org> | 2021-06-08 23:17:31 -0700 |
---|---|---|
committer | Matt Turner <mattst88@gentoo.org> | 2021-06-09 21:23:54 -0700 |
commit | b3c917f7fa73d11c69b7e55dc7a00bc18a18edc7 (patch) | |
tree | be40bee816e700cc25217340cfe087a8ff282a7c /catalyst/lock.py | |
parent | catalyst: Remove clear_dir's never used clear_nondir parameter (diff) | |
download | catalyst-b3c917f7fa73d11c69b7e55dc7a00bc18a18edc7.tar.gz catalyst-b3c917f7fa73d11c69b7e55dc7a00bc18a18edc7.tar.bz2 catalyst-b3c917f7fa73d11c69b7e55dc7a00bc18a18edc7.zip |
catalyst: Replace snakeoil's locks with fasteners
To no great surprise, the existing locking was broken. For example,
clear_chroot() releases the lock. It is called by unpack(), which is
part of prepare_sequence. The result is that the whole build could be
done without holding the lock.
Just lock around run(). It's not apparent that finer-grained locking
does anything for us.
Bug: https://bugs.gentoo.org/791583
Signed-off-by: Matt Turner <mattst88@gentoo.org>
Diffstat (limited to 'catalyst/lock.py')
-rw-r--r-- | catalyst/lock.py | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/catalyst/lock.py b/catalyst/lock.py deleted file mode 100644 index e31745b2..00000000 --- a/catalyst/lock.py +++ /dev/null @@ -1,58 +0,0 @@ - -import os - -from contextlib import contextmanager - -from snakeoil import fileutils -from snakeoil import osutils -from catalyst.fileops import ensure_dirs - - -LockInUse = osutils.LockException - -class Lock: - """ - A fnctl-based filesystem lock - """ - def __init__(self, lockfile): - fileutils.touch(lockfile, mode=0o664) - os.chown(lockfile, uid=-1, gid=250) - self.lock = osutils.FsLock(lockfile) - - def read_lock(self): - self.lock.acquire_read_lock() - - def write_lock(self): - self.lock.acquire_write_lock() - - def unlock(self): - # Releasing a write lock is the same as a read lock. - self.lock.release_write_lock() - -class LockDir(Lock): - """ - A fnctl-based filesystem lock in a directory - """ - def __init__(self, lockdir): - ensure_dirs(lockdir) - lockfile = os.path.join(lockdir, '.catalyst_lock') - - Lock.__init__(self, lockfile) - -@contextmanager -def read_lock(filename): - lock = Lock(filename) - lock.read_lock() - try: - yield - finally: - lock.unlock() - -@contextmanager -def write_lock(filename): - lock = Lock(filename) - lock.write_lock() - try: - yield - finally: - lock.unlock() |