Fix inconsistent clearing of lockfiles in projects

This commit is contained in:
Veronica Berglyd Olsen
2023-07-24 23:29:39 +02:00
parent 7965e3365b
commit 1752d5c5cb
4 changed files with 10 additions and 7 deletions
-1
View File
@@ -407,7 +407,6 @@ class NWProject(QObject):
self._options.saveSettings() self._options.saveSettings()
self._tree.writeToCFile() self._tree.writeToCFile()
self._session.appendSession(idleTime) self._session.appendSession(idleTime)
self._storage.clearLockFile()
self._storage.closeSession() self._storage.closeSession()
self.clearProject() self.clearProject()
self._lockedBy = None self._lockedBy = None
+4 -3
View File
@@ -67,6 +67,7 @@ class NWStorage:
"""Reset internal variables.""" """Reset internal variables."""
self._storagePath = None self._storagePath = None
self._runtimePath = None self._runtimePath = None
self._lockFilePath = None
self._openMode = self.MODE_INACTIVE self._openMode = self.MODE_INACTIVE
return return
@@ -146,7 +147,7 @@ class NWStorage:
def closeSession(self): def closeSession(self):
"""Run tasks related to closing the session.""" """Run tasks related to closing the session."""
# Clear lockfile self.clearLockFile()
self.clear() self.clear()
return return
@@ -189,7 +190,7 @@ class NWStorage:
if item.suffix == ".nwd" and isHandle(item.stem) if item.suffix == ".nwd" and isHandle(item.stem)
] if contentPath else [] ] if contentPath else []
def readLockFile(self) -> list: def readLockFile(self) -> list[str]:
"""Read the project lock file.""" """Read the project lock file."""
if self._lockFilePath is None: if self._lockFilePath is None:
return ["ERROR"] return ["ERROR"]
@@ -198,7 +199,7 @@ class NWStorage:
return [] return []
try: try:
lines = self._lockFilePath.read_text(encoding="utf-8").split(";") lines = self._lockFilePath.read_text(encoding="utf-8").strip().split(";")
except Exception: except Exception:
logger.error("Failed to read project lockfile") logger.error("Failed to read project lockfile")
logException() logException()
+5 -2
View File
@@ -29,6 +29,7 @@ from tools import C, cmpFiles, writeFile, buildTestProject, XML_IGNORE
from novelwriter import CONFIG from novelwriter import CONFIG
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
from novelwriter.constants import nwFiles
from novelwriter.core.tree import NWTree from novelwriter.core.tree import NWTree
from novelwriter.core.index import NWIndex from novelwriter.core.index import NWIndex
from novelwriter.core.project import NWProject from novelwriter.core.project import NWProject
@@ -172,7 +173,8 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
assert theProject.openProject(fncPath) is False assert theProject.openProject(fncPath) is False
# Fail on lock file # Fail on lock file
assert theProject._storage.writeLockFile() theProject.storage._lockFilePath = fncPath / nwFiles.PROJ_LOCK
assert theProject.storage.writeLockFile() is True
assert theProject.openProject(fncPath) is False assert theProject.openProject(fncPath) is False
assert isinstance(theProject.getLockStatus(), list) assert isinstance(theProject.getLockStatus(), list)
@@ -185,7 +187,8 @@ def testCoreProject_Open(monkeypatch, caplog, mockGUI, fncPath, mockRnd):
theProject.closeProject() theProject.closeProject()
# Force open with lockfile # Force open with lockfile
assert theProject._storage.writeLockFile() theProject.storage._lockFilePath = fncPath / nwFiles.PROJ_LOCK
assert theProject.storage.writeLockFile() is True
assert theProject.openProject(fncPath, overrideLock=True) is True assert theProject.openProject(fncPath, overrideLock=True) is True
theProject.closeProject() theProject.closeProject()
assert theProject.getLockStatus() is None assert theProject.getLockStatus() is None
+1 -1
View File
@@ -92,7 +92,7 @@ def testCoreStorage_OpenProjectInPlace(mockGUI, fncPath, mockRnd):
assert isinstance(storage.getXmlWriter(), ProjectXMLWriter) assert isinstance(storage.getXmlWriter(), ProjectXMLWriter)
# Get content # Get content
assert sorted(storage.scanContent()) == sorted([C.hTitlePage, C.hChapterDoc, C.hSceneDoc]) assert sorted(storage.scanContent()) == [C.hTitlePage, C.hChapterDoc, C.hSceneDoc]
# Get document # Get document
assert storage.getDocument(C.hSceneDoc).readDocument() == "### New Scene\n\n" assert storage.getDocument(C.hSceneDoc).readDocument() == "### New Scene\n\n"