Add hash check on document read/write (#890)

* Add sha256sum function
* Add hash check to document class
* Make sha256sum test more thorough
* Handle exceptions in the sha256sum function directly
* Update test coverage
* Clarify title on dialog box
* Don't write blank lines in makeAlert
This commit is contained in:
Veronica Berglyd Olsen
2021-09-19 13:55:54 +02:00
committed by GitHub
parent d65c5e93b6
commit c852a5bda3
6 changed files with 140 additions and 29 deletions
+17 -3
View File
@@ -453,9 +453,23 @@ class GuiDocEditor(QTextEdit):
self.saveCursorPosition()
if not self._nwDocument.writeDocument(docText):
self.theParent.makeAlert([
self.tr("Could not save document."), self._nwDocument.getError()
], nwAlert.ERROR)
saveOk = False
if self._nwDocument._currHash != self._nwDocument._prevHash:
msgYes = self.theParent.askQuestion(
self.tr("File Changed on Disk"),
self.tr(
"This document has been changed outside of novelWriter "
"while it was open. Overvrite the file on disk?"
)
)
if msgYes:
saveOk = self._nwDocument.writeDocument(docText, forceWrite=True)
if not saveOk:
self.theParent.makeAlert([
self.tr("Could not save document."), self._nwDocument.getError()
], nwAlert.ERROR)
return False
self.setDocumentChanged(False)