Ensure atomicity of fs lock

This commit is contained in:
lash 2022-05-05 15:10:05 +00:00
parent 440fab9e70
commit 1951fcda8a
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 12 additions and 13 deletions

View File

@ -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
* Add optional concurrency lock for persistence store, implemented for file store
- 0.2.3

View File

@ -1,6 +1,6 @@
[metadata]
name = shep
version = 0.2.5
version = 0.2.6
description = Multi-state key stores using bit masks
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -28,22 +28,17 @@ class SimpleFileStore:
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):
if self.__lock_path == None:
return
if self.__is_locked(k):
raise StateLockedKey(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()