diff --git a/.travis.yml b/.travis.yml index de4a683a..89ca3727 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ install: - pip install --upgrade pip - pip install -r requirements.txt # - pip install pytest-faulthandler + - pip install PyVirtualDisplay==0.2.5 - pip install pytest-xvfb - pip install pytest-cov - pip install pytest-qt diff --git a/CHANGELOG.md b/CHANGELOG.md index 44965876..462dc91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # novelWriter ChangeLog +## Version 0.7 [2020-xx-xx] + +**Other Changes** + +* Dropped the usage of .bak copies of document files. This was the old method to ensure the document data was written successfully, but it uses twice the storage space. Instead, writing via a temp file is the safe way to save files. PR #248. + ## Not Yet Released **Bugfixes** diff --git a/nw/core/document.py b/nw/core/document.py index 4c502bea..4cfd09a3 100644 --- a/nw/core/document.py +++ b/nw/core/document.py @@ -147,12 +147,10 @@ class NWDoc(): mkdir(dataPath) logger.debug("Created folder %s" % dataPath) - docTemp = path.join(dataPath, docFile+"~") - docBack = path.join(dataPath, docFile[:-3]+"bak") - itemPath = self.theProject.projTree.getItemPath(self.docHandle) docMeta = "%%~ "+":".join(itemPath)+":"+self.theItem.itemName+"\n" + docTemp = path.join(dataPath, docFile+"~") try: with open(docTemp,mode="w",encoding="utf8") as outFile: outFile.write(docMeta) @@ -161,12 +159,16 @@ class NWDoc(): self.makeAlert(["Could not save document.",str(e)], nwAlert.ERROR) return False - # If we're here, the file was successfully saved, - # so let's sort out the temps and backups + # Remove bak files from old file save method, if one exists + # This part can eventually be removed + docBack = path.join(dataPath, docFile[:-3]+"bak") if path.isfile(docBack): unlink(docBack) + + # If we're here, the file was successfully saved, so we can + # replace the temp file with the actual file if path.isfile(docPath): - rename(docPath, docBack) + unlink(docPath) rename(docTemp, docPath) self.theParent.statusBar.setStatus("Saved Document: %s" % self.theItem.itemName) diff --git a/sample/data_b/8136a5a774a0_main.nwd b/sample/data_b/8136a5a774a0_main.nwd index 4e63373d..a304cb35 100644 --- a/sample/data_b/8136a5a774a0_main.nwd +++ b/sample/data_b/8136a5a774a0_main.nwd @@ -1,4 +1,4 @@ -%%~ b8136a5a774a0:98acd8c76c93a:Delete Me! +%%~ b8136a5a774a0:7031beac91f75:Delete Me! ### Delete Me! This scene is trash. \ No newline at end of file diff --git a/sample/data_e/dca4be2fcaf8_main.nwd b/sample/data_e/dca4be2fcaf8_main.nwd index 679e4e27..5fef1f34 100644 --- a/sample/data_e/dca4be2fcaf8_main.nwd +++ b/sample/data_e/dca4be2fcaf8_main.nwd @@ -1,4 +1,4 @@ -%%~ edca4be2fcaf8:7031beac91f75:Part 1 +%%~ edca4be2fcaf8:7031beac91f75:Part One # Part One The first part. \ No newline at end of file diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index ad832035..e114568a 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,5 +1,5 @@ - + Sample Project Sample Project @@ -12,7 +12,7 @@ True 636b6aa9b697b ba8a28a246524 - 914 + 920 B E @@ -73,7 +73,7 @@ False True PAGE - 208 + 210 40 2 213 @@ -89,7 +89,7 @@ 23 5 1 - 0 + 27 A Folder @@ -122,7 +122,7 @@ 1199 216 7 - 527 + 825 Another Scene @@ -135,7 +135,7 @@ 476 93 3 - 551 + 428 Interlude @@ -148,7 +148,7 @@ 633 101 3 - 1238 + 752 A Note on Structure @@ -161,7 +161,7 @@ 1692 313 6 - 1721 + 551 Chapter Two @@ -174,7 +174,7 @@ 139 28 1 - 343 + 242 We Found John! @@ -214,7 +214,7 @@ 49 9 1 - 24 + 65 Jane Smith @@ -227,7 +227,7 @@ 55 9 1 - 25 + 71 Locations @@ -247,7 +247,7 @@ 76 15 1 - 20 + 93 Space @@ -260,7 +260,7 @@ 115 24 1 - 133 + 135 Mars @@ -290,9 +290,9 @@ False True SCENE - 0 - 0 - 0 + 30 + 6 + 1 36