]> git.lyx.org Git - features.git/commitdiff
Rename emergency file when it is kept.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Wed, 16 Jan 2019 16:13:53 +0000 (11:13 -0500)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Fri, 18 Jan 2019 04:01:54 +0000 (23:01 -0500)
Otherwise, we will ask about it again next time, when the file
may have changed. Also, if we crash again, we'll over-write that
file, which we may not want to do.

See bug #11464.

(cherry picked from commit b804e8851c33b68caa5057e809a12333741dfe2e)

src/Buffer.cpp
status.23x

index 460fc910db116c74bda6aae2ca1a219a6994e50f..3130c2357f671f3c697cd425c52c0604c3f2834f 100644 (file)
@@ -4771,6 +4771,32 @@ Buffer::ReadStatus Buffer::loadEmergency()
                                _("&Remove"), _("&Keep"));
                if (del_emerg == 0)
                        emergencyFile.removeFile();
+               else {
+                       // See bug #11464
+                       FileName newname;
+                       string const ename = emergencyFile.absFileName();
+                       bool noname = true;
+                       // Surely we can find one in 100 tries?
+                       for (int i = 1; i < 100; ++i) {
+                               newname.set(ename + to_string(i) + ".lyx");
+                               if (!newname.exists()) {
+                                       noname = false;
+                                       break;
+                               }
+                       }
+                       if (!noname) {
+                               // renameTo returns true on success. So inverting that
+                               // will give us true if we fail.
+                               noname = !emergencyFile.renameTo(newname);
+                       }
+                       if (noname) {
+                               Alert::warning(_("Can't rename emergency file!"),
+                                       _("LyX was unable to rename the emergency file. "
+                                         "You should do so manually. Otherwise, you will be"
+                                         "asked about it again the next time you try to load"
+                                         "this file, and may over-write your own work."));
+                       }
+               }
                return ReadOriginal;
        }
 
index 7032895472bea488dd34f0303a897372420fea6a..836975acb83a8f3974350db9ae78b5bc119052fc 100644 (file)
@@ -88,6 +88,8 @@ What's new
 
 * USER INTERFACE
 
+- Rename emergency file when user wants to save it (bug 11464).
+
 - Fix reloading of local layout file (bug 11120).
 
 - Check for dirty hidden child documents when closing (bug 11405).