string diskfile = filename.toFilesystemEncoding();
if (suffixIs(diskfile, ".emergency"))
diskfile = diskfile.substr(0, diskfile.size() - 10);
- pimpl_->timestamp_ = fs::last_write_time(diskfile);
- pimpl_->checksum_ = sum(FileName(diskfile));
+ saveCheckSum(diskfile);
}
if (file_format != LYX_FORMAT) {
if (writeFile(pimpl_->filename)) {
markClean();
removeAutosaveFile(fileName());
- pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename.toFilesystemEncoding());
- pimpl_->checksum_ = sum(pimpl_->filename);
+ saveCheckSum(pimpl_->filename.toFilesystemEncoding());
return true;
} else {
// Saving failed, so backup is not backup
}
+void Buffer::saveCheckSum(string const & file) const
+{
+ if (fs::exists(file)) {
+ pimpl_->timestamp_ = fs::last_write_time(file);
+ pimpl_->checksum_ = sum(FileName(file));
+ } else {
+ // in the case of save to a new file.
+ pimpl_->timestamp_ = 0;
+ pimpl_->checksum_ = 0;
+ }
+}
+
+
void Buffer::markClean() const
{
if (!pimpl_->lyx_clean) {
/// whether or not disk file has been externally modified
bool isExternallyModified(CheckMethod method) const;
+ /// save timestamp and checksum of the given file.
+ void saveCheckSum(std::string const & file) const;
+
/// mark the main lyx file as not needing saving
void markClean() const;
buffer->markDirty();
bool unnamed = buffer->isUnnamed();
buffer->setUnnamed(false);
+ buffer->saveCheckSum(fname);
if (!menuWrite(buffer)) {
buffer->setFileName(oldname);
buffer->setUnnamed(unnamed);
+ buffer->saveCheckSum(oldname);
return false;
}