From aa4c7e7ef584630338dfca5db45305f2e1865f11 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Sun, 3 May 2009 10:21:21 +0000 Subject: [PATCH] Fix bug #5879 (try 2): Move the autosave file of a buffer when the filename changes. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29507 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 8 ++++++++ src/Buffer.h | 6 ++++-- src/frontends/qt4/GuiView.cpp | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index cdc45a6dde..9970af3181 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2621,6 +2621,14 @@ void Buffer::removeAutosaveFile() const } +void Buffer::moveAutosaveFile(support::FileName const & oldauto) const +{ + FileName const newauto = getAutosaveFilename(); + if (!(oldauto == newauto || oldauto.moveTo(newauto))) + LYXERR0("Unable to remove autosave file `" << oldauto << "'!"); +} + + // Perfect target for a thread... void Buffer::autoSave() const { diff --git a/src/Buffer.h b/src/Buffer.h index dd1a2b4c84..97a940c248 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -468,6 +468,10 @@ public: void autoSave() const; /// void removeAutosaveFile() const; + /// + void moveAutosaveFile(support::FileName const & old) const; + /// + support::FileName getAutosaveFilename() const; /// return the format of the buffer on a string std::string bufferFormat() const; @@ -537,8 +541,6 @@ private: */ ReadStatus readFile(Lexer &, support::FileName const & filename, bool fromString = false); - /// - support::FileName getAutosaveFilename() const; /// Use the Pimpl idiom to hide the internals. class Impl; diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index b33ccc2f6c..fa71523759 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -1818,6 +1818,8 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname) } } + FileName oldauto = b.getAutosaveFilename(); + // Ok, change the name of the buffer b.setFileName(fname.absFilename()); b.markDirty(); @@ -1825,10 +1827,15 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname) b.setUnnamed(false); b.saveCheckSum(fname); + // bring the autosave file with us, just in case. + b.moveAutosaveFile(oldauto); + if (!saveBuffer(b)) { + oldauto = b.getAutosaveFilename(); b.setFileName(oldname.absFilename()); b.setUnnamed(unnamed); b.saveCheckSum(oldname); + b.moveAutosaveFile(oldauto); return false; } -- 2.39.2