Closed bibimbop closed 11 years ago
This is an excellent suggestion. I will investigate next week. I think it may be sufficient to just compare the save timestamps of the document and the meta. Depends if Qt or Python give me a save timestamp that is reliable on all platforms.
Well, the timestamp won't work if the files are copied. Some PPer use directories to store older versions. It's easy to copy the wrong files.
A checksum is the best way to ensure both files are in sync. Python provides the hashlib for that purpose (http://docs.python.org/2/library/hashlib.html).
OK having thought this through I propose:
This takes care of the case where a file was saved before this version and has no DOCHASH metadata.
Going to use QCryptographicHash. Its output is a QByteArray, converts directly to python bytes.
Since hash result can contain any character we convert it to a string with repr which is
smart enough to use double-quote if the string contains a single-quote (and vice versa)
and presumably smart enough to \escape one or the other if needed. But still have to expect
that the document hash could be like 'blah blah"\' etc'
. However, the way the sectionRE works,
the cap(2).trimmed() will pick it up ok.
63819ba
A couple time I went back to a previous version of the text while forgetting to also restore the meta file, and ended-up with discrepancies with the page markers (or so I thought, see issue #113). guiguts has the same issue.
I suggest that when saving, a checksum of the text should be computed and saved in the meta file. When opening the meta file, the checksum should be checked against the text file, and a window warning should be issued if the files don't match.