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
This commit is contained in:
Vincent van Ravesteijn 2009-05-03 10:21:21 +00:00
parent 11ecc24c0c
commit aa4c7e7ef5
3 changed files with 19 additions and 2 deletions

View File

@ -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... // Perfect target for a thread...
void Buffer::autoSave() const void Buffer::autoSave() const
{ {

View File

@ -468,6 +468,10 @@ public:
void autoSave() const; void autoSave() const;
/// ///
void removeAutosaveFile() const; void removeAutosaveFile() const;
///
void moveAutosaveFile(support::FileName const & old) const;
///
support::FileName getAutosaveFilename() const;
/// return the format of the buffer on a string /// return the format of the buffer on a string
std::string bufferFormat() const; std::string bufferFormat() const;
@ -537,8 +541,6 @@ private:
*/ */
ReadStatus readFile(Lexer &, support::FileName const & filename, ReadStatus readFile(Lexer &, support::FileName const & filename,
bool fromString = false); bool fromString = false);
///
support::FileName getAutosaveFilename() const;
/// Use the Pimpl idiom to hide the internals. /// Use the Pimpl idiom to hide the internals.
class Impl; class Impl;

View File

@ -1818,6 +1818,8 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
} }
} }
FileName oldauto = b.getAutosaveFilename();
// Ok, change the name of the buffer // Ok, change the name of the buffer
b.setFileName(fname.absFilename()); b.setFileName(fname.absFilename());
b.markDirty(); b.markDirty();
@ -1825,10 +1827,15 @@ bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
b.setUnnamed(false); b.setUnnamed(false);
b.saveCheckSum(fname); b.saveCheckSum(fname);
// bring the autosave file with us, just in case.
b.moveAutosaveFile(oldauto);
if (!saveBuffer(b)) { if (!saveBuffer(b)) {
oldauto = b.getAutosaveFilename();
b.setFileName(oldname.absFilename()); b.setFileName(oldname.absFilename());
b.setUnnamed(unnamed); b.setUnnamed(unnamed);
b.saveCheckSum(oldname); b.saveCheckSum(oldname);
b.moveAutosaveFile(oldauto);
return false; return false;
} }