Ensure atomicity of fs lock
This commit is contained in:
parent
440fab9e70
commit
1951fcda8a
@ -1,3 +1,7 @@
|
|||||||
|
- 0.2.6
|
||||||
|
* Ensure atomic state lock in fs
|
||||||
|
- 0.2.5
|
||||||
|
* Correct handling of persistent sync when no not-state filter has been set
|
||||||
- 0.2.4
|
- 0.2.4
|
||||||
* Add optional concurrency lock for persistence store, implemented for file store
|
* Add optional concurrency lock for persistence store, implemented for file store
|
||||||
- 0.2.3
|
- 0.2.3
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = shep
|
name = shep
|
||||||
version = 0.2.5
|
version = 0.2.6
|
||||||
description = Multi-state key stores using bit masks
|
description = Multi-state key stores using bit masks
|
||||||
author = Louis Holbrook
|
author = Louis Holbrook
|
||||||
author_email = dev@holbrook.no
|
author_email = dev@holbrook.no
|
||||||
|
@ -28,22 +28,17 @@ class SimpleFileStore:
|
|||||||
os.makedirs(lock_path, exist_ok=True)
|
os.makedirs(lock_path, exist_ok=True)
|
||||||
|
|
||||||
|
|
||||||
def __is_locked(self, k):
|
|
||||||
if self.__lock_path == None:
|
|
||||||
return False
|
|
||||||
for v in os.listdir(self.__lock_path):
|
|
||||||
if k == v:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def __lock(self, k):
|
def __lock(self, k):
|
||||||
if self.__lock_path == None:
|
if self.__lock_path == None:
|
||||||
return
|
return
|
||||||
if self.__is_locked(k):
|
|
||||||
raise StateLockedKey(k)
|
|
||||||
fp = os.path.join(self.__lock_path, k)
|
fp = os.path.join(self.__lock_path, k)
|
||||||
f = open(fp, 'w')
|
f = None
|
||||||
|
try:
|
||||||
|
f = open(fp, 'x')
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
if f == None:
|
||||||
|
raise StateLockedKey(k)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user