From 10764a2041c4beb2a1729332c70182850f96dea8 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:20:49 +0100 Subject: [PATCH] Block overwriting when creating sample project --- novelwriter/core/coretools.py | 7 +++++++ tests/test_core/test_core_coretools.py | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/novelwriter/core/coretools.py b/novelwriter/core/coretools.py index 0552001d..a4e3e3aa 100644 --- a/novelwriter/core/coretools.py +++ b/novelwriter/core/coretools.py @@ -513,6 +513,13 @@ class ProjectBuilder: """Make a copy of the sample project by extracting the sample.zip file to the new path. """ + if path.exists(): + SHARED.error(self.tr( + "The target folder already exists. " + "Please choose another folder." + )) + return False + if (sample := CONFIG.assetPath("sample.zip")).is_file(): try: shutil.unpack_archive(sample, path) diff --git a/tests/test_core/test_core_coretools.py b/tests/test_core/test_core_coretools.py index 2309bd99..85ebedfd 100644 --- a/tests/test_core/test_core_coretools.py +++ b/tests/test_core/test_core_coretools.py @@ -651,7 +651,7 @@ def testCoreTools_ProjectBuilderSample(monkeypatch, mockGUI, fncPath, tstPaths): data = { "name": "Test Sample", "author": "Jane Doe", - "path": fncPath, + "path": fncPath / "project", "sample": True, } @@ -684,6 +684,9 @@ def testCoreTools_ProjectBuilderSample(monkeypatch, mockGUI, fncPath, tstPaths): zipObj.write(docFile, f"content/{docFile.name}") assert builder.buildProject(data) is True + + # Can't create to the same target again + assert builder.buildProject(data) is False dstSample.unlink() # END Test testCoreTools_ProjectBuilderSample