summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2018-07-21 10:39:47 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2018-07-21 10:39:47 -0700
commit2b0d94434164e5d097b8c9d7f7109651b3613b58 (patch)
tree5f511ec5a0f81714ba8b0eef2fa5524ee785c382
parent1a136d6db2d12be8788c34993c5e6f4edeb00bb3 (diff)
downloadspack-2b0d94434164e5d097b8c9d7f7109651b3613b58.tar.gz
spack-2b0d94434164e5d097b8c9d7f7109651b3613b58.tar.bz2
spack-2b0d94434164e5d097b8c9d7f7109651b3613b58.tar.xz
spack-2b0d94434164e5d097b8c9d7f7109651b3613b58.zip
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.
-rw-r--r--lib/spack/llnl/util/lock.py5
-rw-r--r--lib/spack/spack/test/llnl/util/lock.py20
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/lock.py b/lib/spack/llnl/util/lock.py
index 10e552bdb5..b685091e9b 100644
--- a/lib/spack/llnl/util/lock.py
+++ b/lib/spack/llnl/util/lock.py
@@ -150,6 +150,11 @@ class Lock(object):
def _ensure_parent_directory(self):
parent = os.path.dirname(self.path)
+
+ # relative paths to lockfiles in the current directory have no parent
+ if not parent:
+ return '.'
+
try:
os.makedirs(parent)
except OSError as e:
diff --git a/lib/spack/spack/test/llnl/util/lock.py b/lib/spack/spack/test/llnl/util/lock.py
index 7401ecdc2d..89434d82f1 100644
--- a/lib/spack/spack/test/llnl/util/lock.py
+++ b/lib/spack/spack/test/llnl/util/lock.py
@@ -1047,3 +1047,23 @@ def test_lock_with_no_parent_directory(tmpdir):
lock = lk.Lock('foo/bar/baz/lockfile')
with lk.WriteTransaction(lock):
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