Skip to content

Commit 40fb635

Browse files
authored
Feature: os_touch - Ensure that entire folder structure exists (#56)
* 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
1 parent d4da058 commit 40fb635

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

dictdatabase/locking.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class ReadLock(AbstractLock):
182182

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

@@ -217,6 +218,7 @@ class WriteLock(AbstractLock):
217218

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

0 commit comments

Comments
 (0)