Juergen Spitzmueller <[EMAIL PROTECTED]> writes:

| Lars Gullik Bjønnes wrote:
| > Can you try this one Jurgen?
| 
| It fixes the given bug as well as my patch (and gives a nice debug message).
| Note, while you are at it, that there is a similar pending case in 
| buffer::save:
| http://bugzilla.lyx.org/show_bug.cgi?id=2740

You mean something like this:

Index: buffer.C
===================================================================
--- buffer.C    (revision 14846)
+++ buffer.C    (working copy)
@@ -712,14 +712,13 @@
                // good enough. (Lgb)
                // But to use this we need fs::copy_file to actually do a copy,
                // even when the target file exists. (Lgb)
-               if (fs::exists(fileName()) && 
fs::is_writable(fs::path(fileName()).branch_path())) {
-                 //try {
+               try {
                    fs::copy_file(fileName(), s, false);
-                   //}
-                   //catch (fs::filesystem_error const & fe) {
-                   //lyxerr << "LyX was not able to make backup copy. 
Beware.\n"
-                   //     << fe.what() << endl;
-                   //}
+               }
+               catch (fs::filesystem_error const & fe) {
+                       lyxerr << "LyX was not able to make backup copy."
+                              <<" Beware.\n"
+                              << fe.what() << endl;
                }
        }



Resulting function:

// Should probably be moved to somewhere else: BufferView? LyXView?
bool Buffer::save() const
{
        // We don't need autosaves in the immediate future. (Asger)
        resetAutosaveTimers();

        // make a backup
        string s;
        if (lyxrc.make_backup) {
                s = fileName() + '~';
                if (!lyxrc.backupdir_path.empty())
                        s = addName(lyxrc.backupdir_path,
                                    subst(os::internal_path(s),'/','!'));

                // It might very well be that this variant is just
                // good enough. (Lgb)
                // But to use this we need fs::copy_file to actually do a copy,
                // even when the target file exists. (Lgb)
                try {
                        fs::copy_file(fileName(), s, false);
                }
                catch (fs::filesystem_error const & fe) {
                        lyxerr << "LyX was not able to make backup copy."
                               <<" Beware.\n"
                               << fe.what() << endl;
                }
        }

        if (writeFile(fileName())) {
                markClean();
                removeAutosaveFile(fileName());
        } else {
                // Saving failed, so backup is not backup
                if (lyxrc.make_backup)
                        rename(s, fileName());
                return false;
        }
        return true;
}

-- 
        Lgb

Reply via email to