From baf76100b9464ff54772e583134517e1e049a1fe Mon Sep 17 00:00:00 2001 From: Michael Schmitt Date: Sun, 14 Jan 2007 17:31:15 +0000 Subject: [PATCH] * src/buffer.C: save(): use correct filesystem encoding; check whether backup was successful git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16681 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index 1fe5db90ff..2944521d08 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -752,41 +752,40 @@ bool Buffer::save() const // We don't need autosaves in the immediate future. (Asger) resetAutosaveTimers(); + string const encodedFilename = pimpl_->filename.toFilesystemEncoding(); + + FileName backupName; + bool madeBackup = false; + // make a backup if the file already exists - string s; - if (lyxrc.make_backup && fs::exists(pimpl_->filename.toFilesystemEncoding())) { - s = fileName() + '~'; + if (lyxrc.make_backup && fs::exists(encodedFilename)) { + backupName = FileName(fileName() + '~'); if (!lyxrc.backupdir_path.empty()) - s = addName(lyxrc.backupdir_path, - subst(os::internal_path(s),'/','!')); + backupName = FileName(addName(lyxrc.backupdir_path, + subst(os::internal_path(backupName.absFilename()), '/', '!'))); - // 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(pimpl_->filename.toFilesystemEncoding(), s, false); - } - catch (fs::filesystem_error const & fe) { + fs::copy_file(encodedFilename, backupName.toFilesystemEncoding(), false); + madeBackup = true; + } catch (fs::filesystem_error const & fe) { Alert::error(_("Backup failure"), - bformat(_("LyX was not able to make a backup copy in %1$s.\n" - "Please check if the directory exists and is writeable."), - from_utf8(fs::path(s).branch_path().native_directory_string()))); - lyxerr[Debug::DEBUG] << "Fs error: " - << fe.what() << endl; + bformat(_("Cannot create backup file %1$s.\n" + "Please check whether the directory exists and is writeable."), + from_utf8(backupName.absFilename()))); + lyxerr[Debug::DEBUG] << "Fs error: " << fe.what() << endl; } } if (writeFile(pimpl_->filename)) { markClean(); removeAutosaveFile(fileName()); + return true; } else { // Saving failed, so backup is not backup - if (lyxrc.make_backup) - rename(FileName(s), pimpl_->filename); + if (madeBackup) + rename(backupName, pimpl_->filename); return false; } - return true; } -- 2.39.5