Richard Heck wrote:
>> wouldnt be better this way
>> // Saving failed, so backup is not backup
>>                  if (madeBackup)
>>                           backupName.moveTo(d->filename);
>> +                        d->filename.copyTo(d->backupName);
>>
>>
>>    
> I'm a bit puzzled here. Why can't we just move the backup file back to 
> where it was and do nothing else? Is the thought that we ought to have a 
> backup? Having two copies of the file doesn't help much.

you are right, all other things look like overengineering.
attaching the fixed version.

pavel
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index cdea9e6..27d0fe9 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -975,6 +975,17 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
 // Should probably be moved to somewhere else: BufferView? GuiView?
 bool Buffer::save() const
 {
+	// ask if the disk file has been externally modified (use checksum method)
+	if (fileName().exists() && isExternallyModified(checksum_method)) {
+		docstring const file = makeDisplayPath(absFileName(), 20);
+		docstring text = bformat(_("Document %1$s has been externally modified. Are you sure "
+							     "you want to overwrite this file?"), file);
+		int const ret = Alert::prompt(_("Overwrite modified file?"),
+			text, 1, 1, _("&Overwrite"), _("&Cancel"));
+		if (ret == 1)
+			return false;
+	}
+
 	// We don't need autosaves in the immediate future. (Asger)
 	resetAutosaveTimers();
 
@@ -990,7 +1001,7 @@ bool Buffer::save() const
 			backupName = FileName(addName(lyxrc.backupdir_path,
 						      mangledName));
 		}
-		if (fileName().copyTo(backupName)) {
+		if (fileName().moveTo(backupName)) {
 			madeBackup = true;
 		} else {
 			Alert::error(_("Backup failure"),
@@ -1001,17 +1012,6 @@ bool Buffer::save() const
 		}
 	}
 
-	// ask if the disk file has been externally modified (use checksum method)
-	if (fileName().exists() && isExternallyModified(checksum_method)) {
-		docstring const file = makeDisplayPath(absFileName(), 20);
-		docstring text = bformat(_("Document %1$s has been externally modified. Are you sure "
-							     "you want to overwrite this file?"), file);
-		int const ret = Alert::prompt(_("Overwrite modified file?"),
-			text, 1, 1, _("&Overwrite"), _("&Cancel"));
-		if (ret == 1)
-			return false;
-	}
-
 	if (writeFile(d->filename)) {
 		markClean();
 		return true;
@@ -1050,7 +1050,8 @@ bool Buffer::writeFile(FileName const & fname) const
 		return false;
 	}
 
-	removeAutosaveFile();
+	// see bug 6587
+	// removeAutosaveFile();
 
 	saveCheckSum(d->filename);
 	message(str + _(" done."));
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 09dae40..62c3b56 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -2304,6 +2304,7 @@ bool GuiView::closeBuffer(Buffer & buf)
 		guiApp->gotoBookmark(i+1, false, false);
 
 	if (saveBufferIfNeeded(buf, false)) {
+		buf.removeAutosaveFile();
 		theBufferList().release(&buf);
 		return true;
 	}
@@ -2376,7 +2377,8 @@ bool GuiView::saveBufferIfNeeded(Buffer & buf, bool hiding)
 		// if we crash after this we could
 		// have no autosave file but I guess
 		// this is really improbable (Jug)
-		buf.removeAutosaveFile();
+		// Sometime improbable things happen, bug 6857 (ps)
+		// buf.removeAutosaveFile();
 		if (hiding)
 			// revert all changes
 			buf.reload();

Reply via email to