1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 15:57:14 +03:00

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.
This commit is contained in:
Athanasius 2021-03-13 14:49:21 +00:00
parent 60c67723ca
commit 1cd0392527

View File

@ -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')