From 492d94ee6e19a519638ff6145cd37d09e964e057 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 5 Feb 2023 18:12:50 +0100 Subject: [PATCH] Check that content path exists before returning it from storage class (#1317) --- novelwriter/core/storage.py | 10 +++++++++- tests/test_core/test_core_tree.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/novelwriter/core/storage.py b/novelwriter/core/storage.py index d1cb0b87..2cd4c3d9 100644 --- a/novelwriter/core/storage.py +++ b/novelwriter/core/storage.py @@ -79,8 +79,16 @@ class NWStorage: @property def contentPath(self): + """Return the path used for project content. The folder must + already exist, otherwise this property is None. + """ if self._runtimePath is not None: - return self._runtimePath / "content" + contentPath = self._runtimePath / "content" + if contentPath.is_dir(): + return contentPath + else: + logger.error("Path not found: %s", contentPath) + return None return None ## diff --git a/tests/test_core/test_core_tree.py b/tests/test_core/test_core_tree.py index 7b9d02da..0a6ab099 100644 --- a/tests/test_core/test_core_tree.py +++ b/tests/test_core/test_core_tree.py @@ -469,6 +469,7 @@ def testCoreTree_ToCFile(monkeypatch, mockGUI, mockItems, tmpPath): assert theTree.writeToCFile() is False theProject._storage._runtimePath = tmpPath + (tmpPath / "content").mkdir() assert theTree.writeToCFile() is True pathA = str(Path("content") / "c000000000001.nwd")