summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2018-09-27 09:07:07 +0200
committerEike Ziller <eike.ziller@qt.io>2018-09-27 09:07:07 +0200
commit6507db19e481a60441478588f47d6f6b8689923f (patch)
treeeab50de52aad3bc49510cbbc7c2415cea0d55da6 /src
parent6f56feef29af3f6d6ff7bc490f825550d75d2a9c (diff)
parent8d609692b397f2fad522ec35a430f92bf691f44d (diff)
downloadqt-creator-6507db19e481a60441478588f47d6f6b8689923f.tar.gz
Merge remote-tracking branch 'origin/4.7' into 4.8
Change-Id: Ia215af4ddad73053582284d3ce8d56b92dbbc8f3
Diffstat (limited to 'src')
-rw-r--r--src/libs/utils/savefile.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/libs/utils/savefile.cpp b/src/libs/utils/savefile.cpp
index 36b515568e..5864ece3ef 100644
--- a/src/libs/utils/savefile.cpp
+++ b/src/libs/utils/savefile.cpp
@@ -128,19 +128,32 @@ bool SaveFile::commit()
fileName().toStdWString().data(),
nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr);
if (!result) {
- const DWORD replaceErrorCode = GetLastError();
+ DWORD replaceErrorCode = GetLastError();
QString errorStr;
if (!QFile::exists(finalFileName)) {
// Replace failed because finalFileName does not exist, try rename.
if (!(result = rename(finalFileName)))
errorStr = errorString();
} else {
- wchar_t messageBuffer[256];
- FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- nullptr, replaceErrorCode,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- messageBuffer, sizeof(messageBuffer), nullptr);
- errorStr = QString::fromWCharArray(messageBuffer);
+ if (replaceErrorCode == ERROR_UNABLE_TO_REMOVE_REPLACED) {
+ // If we do not get the rights to remove the original final file we still might try
+ // to replace the file contents
+ result = MoveFileEx(fileName().toStdWString().data(),
+ finalFileName.toStdWString().data(),
+ MOVEFILE_COPY_ALLOWED
+ | MOVEFILE_REPLACE_EXISTING
+ | MOVEFILE_WRITE_THROUGH);
+ if (!result)
+ replaceErrorCode = GetLastError();
+ }
+ if (!result) {
+ wchar_t messageBuffer[256];
+ FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr, replaceErrorCode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ messageBuffer, sizeof(messageBuffer), nullptr);
+ errorStr = QString::fromWCharArray(messageBuffer);
+ }
}
if (!result) {
remove();