From 1cd0392527d4975171540628e98d3f4e346eba63 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Sat, 13 Mar 2021 14:49:21 +0000 Subject: [PATCH] Record if JournalLock.obtain_lock() succeeded, use in release_lock() In the scenario of the default Journals location not even existing the user needs might update it to a network mount. When they do so we attempt, and fail, to unlock the old location, despite it not being locked. So now we have this boolean so we know if we should even attempt unlocking. --- journal_lock.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/journal_lock.py b/journal_lock.py index 8dab6ddc..e947ffe1 100644 --- a/journal_lock.py +++ b/journal_lock.py @@ -37,6 +37,7 @@ class JournalLock: self.journal_dir_lockfile_name: Optional[pathlib.Path] = None # We never test truthiness of this, so let it be defined when first assigned. Avoids type hint issues. # self.journal_dir_lockfile: Optional[IO] = None + self.locked = False def obtain_lock(self) -> JournalLockResult: """ @@ -91,6 +92,8 @@ class JournalLock: self.journal_dir_lockfile.flush() logger.trace('Done') + self.locked = True + return JournalLockResult.LOCKED def release_lock(self) -> bool: @@ -99,6 +102,9 @@ class JournalLock: :return: bool - Success of unlocking operation. """ + if not self.locked: + return True # We weren't locked, and still aren't + unlocked = False if platform == 'win32': logger.trace('win32, using msvcrt')