locks: fix bug when creating lockfiles in the current directory.
- Fixes a bug in `llnl.util.lock` - Locks in the current directory would fail because the parent directory was the empty string. - Fix this and return '.' for the parent of locks in the current directory.
This commit is contained in:
parent
1a136d6db2
commit
2b0d944341
@ -150,6 +150,11 @@ def _lock(self, op, timeout=_default_timeout):
|
|||||||
|
|
||||||
def _ensure_parent_directory(self):
|
def _ensure_parent_directory(self):
|
||||||
parent = os.path.dirname(self.path)
|
parent = os.path.dirname(self.path)
|
||||||
|
|
||||||
|
# relative paths to lockfiles in the current directory have no parent
|
||||||
|
if not parent:
|
||||||
|
return '.'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(parent)
|
os.makedirs(parent)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -1047,3 +1047,23 @@ def test_lock_with_no_parent_directory(tmpdir):
|
|||||||
lock = lk.Lock('foo/bar/baz/lockfile')
|
lock = lk.Lock('foo/bar/baz/lockfile')
|
||||||
with lk.WriteTransaction(lock):
|
with lk.WriteTransaction(lock):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_lock_in_current_directory(tmpdir):
|
||||||
|
"""Make sure locks work even when their parent directory does not exist."""
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
# test we can create a lock in the current directory
|
||||||
|
lock = lk.Lock('lockfile')
|
||||||
|
for i in range(10):
|
||||||
|
with lk.ReadTransaction(lock):
|
||||||
|
pass
|
||||||
|
with lk.WriteTransaction(lock):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# and that we can do the same thing after it's already there
|
||||||
|
lock = lk.Lock('lockfile')
|
||||||
|
for i in range(10):
|
||||||
|
with lk.ReadTransaction(lock):
|
||||||
|
pass
|
||||||
|
with lk.WriteTransaction(lock):
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user