From df396b9e698bbc97157113f671513c8c592e72fe Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 12 Nov 2021 17:41:42 +0100 Subject: [PATCH] Fix reload false alarm from the network drive This regression is due to the saving routine's change: https://github.com/notepad-plus-plus/notepad-plus-plus/commit/9aa9ecb664bd03f3a61cc42891f125492767e066 Normally, on each save, buffer's timestamp is updated for the future comparison with the timestamp on the disk, in order to detect the modification from outside. It seems the new saving routing makes the change (ONLY on network disk) with the timestamp before buffer's timestamp, for unknown reason. The fix is: if timestamp got directly from the file on disk is earlier than buffer's timestamp, it's an absurd case and we ignore it. The buffer's timestamp will be only updated if the file on disk timestamp is later than buffer's one. Fix #10688, fix #10753, fix #10757, close #10774 --- PowerEditor/src/ScintillaComponent/Buffer.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 8cf6c51cb..b10235eb8 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -132,18 +132,24 @@ void Buffer::setLangType(LangType lang, const TCHAR* userLangName) void Buffer::updateTimeStamp() { - FILETIME timeStamp = {}; + FILETIME timeStampLive = {}; WIN32_FILE_ATTRIBUTE_DATA attributes; if (GetFileAttributesEx(_fullPathName.c_str(), GetFileExInfoStandard, &attributes) != 0) { - timeStamp = attributes.ftLastWriteTime; + timeStampLive = attributes.ftLastWriteTime; } - if (CompareFileTime(&_timeStamp, &timeStamp) != 0) + LONG res = CompareFileTime(&_timeStamp, &timeStampLive); + if (res == -1) // timeStampLive is later, it means the file has been modified outside of Notepad++ { - _timeStamp = timeStamp; + _timeStamp = timeStampLive; doNotify(BufferChangeTimestamp); } + else if (res == 1) // timeStampLive (get directly from the file on disk) is earlier than buffer's timestamp - abnormal case + { + // This absurd case can be ignored + } + // else res == 0 => nothing to change } @@ -263,13 +269,20 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it _isFileReadOnly = isFileReadOnly; mask |= BufferChangeReadonly; } - if (CompareFileTime(&_timeStamp, &attributes.ftLastWriteTime) != 0) + + LONG res = CompareFileTime(&_timeStamp, &attributes.ftLastWriteTime); + if (res == -1) // // attributes.ftLastWriteTime is later, it means the file has been modified outside of Notepad++ { _timeStamp = attributes.ftLastWriteTime; mask |= BufferChangeTimestamp; _currentStatus = DOC_MODIFIED; mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified } + else if (res == 1) // The timestamp get directly from the file on disk is earlier than buffer's timestamp - abnormal case + { + // This absurd case can be ignored + } + // else res == 0 => nothing to change if (mask != 0) { @@ -628,8 +641,9 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin newBuf->_currentStatus = DOC_UNNAMED; } - const FILETIME zeroTime = {}; - if (CompareFileTime(&fileNameTimestamp, &zeroTime) != 0) + const FILETIME zeroTimeStamp = {}; + LONG res = CompareFileTime(&fileNameTimestamp, &zeroTimeStamp); + if (res != 0) // res == 1 or res == -1 newBuf->_timeStamp = fileNameTimestamp; _buffers.push_back(newBuf);