1.1 --- a/imiptools/filesys.py Thu Sep 10 00:47:16 2015 +0200
1.2 +++ b/imiptools/filesys.py Thu Sep 10 20:06:16 2015 +0200
1.3 @@ -82,6 +82,7 @@
1.4 "Basic filesystem operations."
1.5
1.6 lock_name = "__lock__"
1.7 + old_lock_name = "__unlock__"
1.8
1.9 def __init__(self, store_dir):
1.10 self.store_dir = store_dir
1.11 @@ -156,19 +157,29 @@
1.12
1.13 parts = parts and list(parts) or []
1.14 parts.append(self.lock_name)
1.15 + mkdir(self.get_object_in_store(*parts))
1.16 parts.append(str(getpid()))
1.17 - makedirs(self.get_object_in_store(*parts))
1.18 + mkdir(self.get_object_in_store(*parts))
1.19
1.20 def remove_lock_dir(self, *parts):
1.21
1.22 "Remove the lock directory defined by the given 'parts'."
1.23
1.24 parts = parts and list(parts) or []
1.25 + target = parts[:]
1.26 +
1.27 + # Move the directory.
1.28 +
1.29 parts.append(self.lock_name)
1.30 - parts.append(str(getpid()))
1.31 - rmdir(self.get_object_in_store(*parts))
1.32 - parts.pop()
1.33 - rmdir(self.get_object_in_store(*parts))
1.34 + target.append(self.old_lock_name)
1.35 + rename(self.get_object_in_store(*parts), self.get_object_in_store(*target))
1.36 +
1.37 + # Then remove the moved directory and its contents.
1.38 +
1.39 + target.append(str(getpid()))
1.40 + rmdir(self.get_object_in_store(*target))
1.41 + target.pop()
1.42 + rmdir(self.get_object_in_store(*target))
1.43
1.44 def owning_lock_dir(self, *parts):
1.45