mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-27 19:40:10 +00:00
Fix bug 4193: Revert and saveAs treated as "file is externally modified"
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_5_X@20108 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
6250d717f2
commit
4c43b3465f
@ -133,6 +133,7 @@ using support::subst;
|
||||
using support::tempName;
|
||||
using support::trim;
|
||||
using support::sum;
|
||||
using support::suffixIs;
|
||||
|
||||
namespace Alert = frontend::Alert;
|
||||
namespace os = support::os;
|
||||
@ -696,6 +697,19 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
|
||||
int const file_format = convert<int>(tmp_format);
|
||||
//lyxerr << "format: " << file_format << endl;
|
||||
|
||||
// save timestamp and checksum of the original disk file, making sure
|
||||
// to not overwrite them with those of the file created in the tempdir
|
||||
// when it has to be converted to the current format.
|
||||
if (!pimpl_->checksum_) {
|
||||
// Save the timestamp and checksum of disk file. If filename is an
|
||||
// emergency file, save the timestamp and sum of the original lyx file
|
||||
// because isExternallyModified will check for this file. (BUG4193)
|
||||
string diskfile = filename.toFilesystemEncoding();
|
||||
if (suffixIs(diskfile, ".emergency"))
|
||||
diskfile = diskfile.substr(0, diskfile.size() - 10);
|
||||
saveCheckSum(diskfile);
|
||||
}
|
||||
|
||||
if (file_format != LYX_FORMAT) {
|
||||
|
||||
if (fromstring)
|
||||
@ -762,9 +776,6 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
|
||||
//MacroTable::localMacros().clear();
|
||||
|
||||
pimpl_->file_fully_loaded = true;
|
||||
// save the timestamp and checksum of disk file
|
||||
pimpl_->timestamp_ = fs::last_write_time(filename.toFilesystemEncoding());
|
||||
pimpl_->checksum_ = sum(filename);
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -813,8 +824,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
|
||||
@ -1589,6 +1599,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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -194,10 +194,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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user