From c669bdc19fef6eae4eab5721667d41f423758051 Mon Sep 17 00:00:00 2001 From: Antoni Baum Date: Fri, 22 Nov 2024 18:36:36 -0800 Subject: [PATCH] Fix inner/outer for write --- src/filelock/read_write/_api.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/filelock/read_write/_api.py b/src/filelock/read_write/_api.py index cde4537..0c5194f 100644 --- a/src/filelock/read_write/_api.py +++ b/src/filelock/read_write/_api.py @@ -205,9 +205,16 @@ def acquire( lock.release() """ - with self._outer_lock: - self._inner_lock.acquire() - return AcquireReturnProxy(lock=self) + if self.read_write_mode == ReadWriteMode.READ: + with self._outer_lock: + self._inner_lock.acquire() + return AcquireReturnProxy(lock=self) + elif self.read_write_mode == ReadWriteMode.WRITE: + self._outer_lock.acquire() + with self._inner_lock: + # Just acquire. + pass + return AcquireReturnProxy(lock=self) def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002 """ @@ -217,7 +224,10 @@ def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002 :param force: If true, the lock counter is ignored and the lock is released in every case/ """ - self._inner_lock.release(force=force) + if self.read_write_mode == ReadWriteMode.READ: + self._inner_lock.release(force=force) + elif self.read_write_mode == ReadWriteMode.WRITE: + self._outer_lock.release(force=force) def __enter__(self) -> Self: """