From: Bo Peng Date: Thu, 6 Sep 2007 15:54:17 +0000 (+0000) Subject: Fix another prompt for externally-modified bug with writeAs() X-Git-Tag: 1.6.10~8461 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=726c8660f0536bdf5e28d5411c5d6b0bf8bb9dbc;p=lyx.git Fix another prompt for externally-modified bug with writeAs() git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20107 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 3eeb7d0d1b..dc2d85f9d2 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -756,8 +756,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename, string diskfile = filename.toFilesystemEncoding(); if (suffixIs(diskfile, ".emergency")) diskfile = diskfile.substr(0, diskfile.size() - 10); - pimpl_->timestamp_ = fs::last_write_time(diskfile); - pimpl_->checksum_ = sum(FileName(diskfile)); + saveCheckSum(diskfile); } if (file_format != LYX_FORMAT) { @@ -874,8 +873,7 @@ bool Buffer::save() const if (writeFile(pimpl_->filename)) { markClean(); removeAutosaveFile(fileName()); - pimpl_->timestamp_ = fs::last_write_time(pimpl_->filename.toFilesystemEncoding()); - pimpl_->checksum_ = sum(pimpl_->filename); + saveCheckSum(pimpl_->filename.toFilesystemEncoding()); return true; } else { // Saving failed, so backup is not backup @@ -1634,6 +1632,19 @@ bool Buffer::isExternallyModified(CheckMethod method) const } +void Buffer::saveCheckSum(string const & file) const +{ + if (fs::exists(file)) { + pimpl_->timestamp_ = fs::last_write_time(file); + pimpl_->checksum_ = sum(FileName(file)); + } else { + // in the case of save to a new file. + pimpl_->timestamp_ = 0; + pimpl_->checksum_ = 0; + } +} + + void Buffer::markClean() const { if (!pimpl_->lyx_clean) { diff --git a/src/Buffer.h b/src/Buffer.h index 6e5ba14546..7d18ab65e2 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -229,6 +229,9 @@ public: /// whether or not disk file has been externally modified bool isExternallyModified(CheckMethod method) const; + /// save timestamp and checksum of the given file. + void saveCheckSum(std::string const & file) const; + /// mark the main lyx file as not needing saving void markClean() const; diff --git a/src/callback.cpp b/src/callback.cpp index 87da777504..2a41494be6 100644 --- a/src/callback.cpp +++ b/src/callback.cpp @@ -195,10 +195,12 @@ bool writeAs(Buffer * buffer, string const & newname) buffer->markDirty(); bool unnamed = buffer->isUnnamed(); buffer->setUnnamed(false); + buffer->saveCheckSum(fname); if (!menuWrite(buffer)) { buffer->setFileName(oldname); buffer->setUnnamed(unnamed); + buffer->saveCheckSum(oldname); return false; }