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