Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Jul 14, 2024
2 parents 81dd98e + 7140788 commit b7da56a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions novelwriter/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def openProject(self, projPath: str | Path, clearLock: bool = False) -> bool:
self.setProjectChanged(False)
self._valid = True
self._state = NWProjectState.READY
self._storage.lockSession() # Lock only after a successful open. See issue #1977.

SHARED.newStatusMessage(self.tr("Opened Project: {0}").format(self._data.name))

Expand Down
7 changes: 6 additions & 1 deletion novelwriter/core/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def initProjectStorage(self, path: str | Path, clearLock: bool = False) -> NWSto
if child.is_dir() and child.name.startswith("data_"):
legacy.legacyDataFolder(basePath, child)

self._writeLockFile()
self._ready = True

return NWStorageOpen.READY
Expand All @@ -249,6 +248,12 @@ def runPostSaveTasks(self, autoSave: bool = False) -> bool: # pragma: no cover
return True
return True

def lockSession(self) -> None:
"""Lock the session when the project is successfully opened."""
if self._ready:
self._writeLockFile()
return

def closeSession(self) -> None:
"""Run tasks related to closing the session."""
self._clearLockFile()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_core/test_core_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def testCoreStorage_InitProjectStorage(monkeypatch, mockGUI, fncPath, mockRnd):
storage.clear()

# Open twice, where second should fail due to lockfile
# Note that locking is only possible after a successful open
assert storage.initProjectStorage(fncPath) == NWStorageOpen.READY
storage.lockSession()
assert storage.initProjectStorage(fncPath) == NWStorageOpen.LOCKED
assert isinstance(storage.lockStatus, list)
assert len(storage.lockStatus) == 4
Expand Down

0 comments on commit b7da56a

Please sign in to comment.