Skip to content

Commit

Permalink
Feature: os_touch - Ensure that entire folder structure exists (#56)
Browse files Browse the repository at this point in the history
* os_touch: Ensure that entire folder structure exists

This is done to avoid a crash when taking a ReadLock while reading a folder of objects.

* Moved os.makedirs to _lock of ReadLock and WriteLock
  • Loading branch information
PeterSR authored Aug 25, 2023
1 parent d4da058 commit 40fb635
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dictdatabase/locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class ReadLock(AbstractLock):

def _lock(self) -> None:
# Express intention to acquire read lock
os.makedirs(os.path.dirname(self.need_lock.path), exist_ok=True)
os_touch(self.need_lock.path)
self.snapshot = FileLocksSnapshot(self.need_lock)

Expand Down Expand Up @@ -217,6 +218,7 @@ class WriteLock(AbstractLock):

def _lock(self) -> None:
# Express intention to acquire write lock
os.makedirs(os.path.dirname(self.need_lock.path), exist_ok=True)
os_touch(self.need_lock.path)
self.snapshot = FileLocksSnapshot(self.need_lock)

Expand Down

0 comments on commit 40fb635

Please sign in to comment.