shep

Multi-state key stores using bit masks for python3
git clone git://git.defalsify.org/shep.git
Log | Files | Refs | LICENSE

commit 1951fcda8a1a434f555699c2a8f5fac76f059f3a
parent 440fab9e70811f7c2fe486ed6138a996d2310f96
Author: lash <dev@holbrook.no>
Date:   Thu,  5 May 2022 15:10:05 +0000

Ensure atomicity of fs lock

Diffstat:
MCHANGELOG | 4++++
Msetup.cfg | 2+-
Mshep/store/file.py | 19+++++++------------
3 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -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 diff --git a/setup.cfg b/setup.cfg @@ -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 diff --git a/shep/store/file.py b/shep/store/file.py @@ -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()