summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2014-05-02 09:00:28 -0500
committerSkip Montanaro <skip@pobox.com>2014-05-02 09:00:28 -0500
commitfe31f0c68ac034df9fe0f4fc1ddb704e2e6f87b5 (patch)
treeca68a8ec6668f7151af82154d58be6e5e8c4ca1a
parent58c3832d4b99cc33218c2d7af04a54272602b511 (diff)
parente80eeddef17cf92d8c3974b491d5001377f8eff8 (diff)
downloadlockfile-fe31f0c68ac034df9fe0f4fc1ddb704e2e6f87b5.tar.gz
Merge pull request #3 from cizra/issue-20
Bugfix: locking two different files in the same directory caused an error during the last unlocking
-rw-r--r--lockfile/__init__.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/lockfile/__init__.py b/lockfile/__init__.py
index 668b426..d905af9 100644
--- a/lockfile/__init__.py
+++ b/lockfile/__init__.py
@@ -174,10 +174,19 @@ class LockBase:
else:
self.tname = ""
dirname = os.path.dirname(self.lock_file)
+
+ # unique name is mostly about the current process, but must
+ # also contain the path -- otherwise, two adjacent locked
+ # files conflict (one file gets locked, creating lock-file and
+ # unique file, the other one gets locked, creating lock-file
+ # and overwriting the already existing lock-file, then one
+ # gets unlocked, deleting both lock-file and unique file,
+ # finally the last lock errors out upon releasing.
self.unique_name = os.path.join(dirname,
- "%s%s.%s" % (self.hostname,
- self.tname,
- self.pid))
+ "%s%s.%s%s" % (self.hostname,
+ self.tname,
+ self.pid,
+ hash(self.path)))
self.timeout = timeout
def acquire(self, timeout=None):