summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Brown <ben.brown@codethink.co.uk>2017-06-27 10:49:19 +0100
committerBen Brown <ben.brown@codethink.co.uk>2017-09-26 14:31:50 +0100
commit9deeb964eadc1d6bf2e18244fb6b5347c5d6a1f0 (patch)
tree95582735d3e7197323a359cac8762dd2bd7878b5
parent4069d2e386f6b5e9f13407502fefd32a3b9c45da (diff)
downloadybd-9deeb964eadc1d6bf2e18244fb6b5347c5d6a1f0.tar.gz
Only delete file if this process (thread) locked it and has finished with it
-rw-r--r--ybd/assembly.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/ybd/assembly.py b/ybd/assembly.py
index 3276138..1ea9664 100644
--- a/ybd/assembly.py
+++ b/ybd/assembly.py
@@ -210,8 +210,10 @@ def shuffle(contents):
@contextlib.contextmanager
def claim(dn):
with open(lockfile(dn), 'a') as L:
+ locked = False
try:
fcntl.flock(L, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ locked = True
except IOError as e:
if e.errno in (errno.EACCES, errno.EAGAIN):
# flock() will report EACCESS or EAGAIN when the lock fails.
@@ -224,7 +226,7 @@ def claim(dn):
try:
yield
finally:
- if os.path.isfile(lockfile(dn)):
+ if locked and os.path.isfile(lockfile(dn)):
os.remove(lockfile(dn))