So with Vincent's cleanup, we now have:
Buffer::ReadStatus Buffer::readAutosave(FileName const & fn)
{
// Now check if autosave file is newer.
FileName const autosaveFile = getAutosaveFileNameFor(fn);
if (!autosaveFile.exists()
|| autosaveFile.lastModified() <= fn.lastModified())
return ReadFileNotFound;
docstring const file = makeDisplayPath(fn.absFileName(), 20);
docstring const text = bformat(_("The backup of the document %1$s "
"is newer.\n\nLoad the backup instead?"), file);
int const ret = Alert::prompt(_("Load backup?"), text, 0, 2,
_("&Load backup"), _("Load &original"), _("&Cancel"));
switch (ret)
{
case 0: {
ReadStatus const ret_rf = readFile(autosaveFile);
// the file is not saved if we load the autosave file.
if (ret_rf == ReadSuccess) {
markDirty();
saveCheckSum(fn);
return ReadSuccess;
}
return ReadAutosaveFailure;
}
case 1:
// Here we delete the autosave
autosaveFile.removeFile();
return ReadOriginal;
default:
break;
}
return ReadCancel;
}
As John said, it looks to me as if we remove the autosave file at the
wrong time: What if the attempt to read the original file fails? It
seems to me that we should remove it (a) if we read it successfully; (b)
if we read the original successfully. That would be the attached patch.
Does this seem right?
Richard
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revision 35834)
+++ src/Buffer.cpp (working copy)
@@ -3693,14 +3693,13 @@
// the file is not saved if we load the autosave file.
if (ret_rf == ReadSuccess) {
markDirty();
+ autosaveFile.removeFile();
saveCheckSum(fn);
return ReadSuccess;
}
return ReadAutosaveFailure;
}
case 1:
- // Here we delete the autosave
- autosaveFile.removeFile();
return ReadOriginal;
default:
break;
@@ -3725,7 +3724,13 @@
if (ret_ra == ReadSuccess || ret_ra == ReadCancel)
return ret_ra;
- return readFile(fn);
+ ReadStatus const success = readFile(fn);
+ if (success == ReadSuccess) {
+ FileName const autosaveFile = getAutosaveFileNameFor(fn);
+ if (!autosaveFile.exists())
+ autosaveFile.removeFile();
+ }
+ return success;
}