forked from qt-creator/qt-creator
Utils: Add env to disable special win32 code
Change-Id: I450152a4d049461b98416fa61a9a1e7082625ecc Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -129,7 +129,10 @@ bool SaveFile::commit()
|
|||||||
|
|
||||||
FilePath finalFileName = m_finalFilePath.resolveSymlinks();
|
FilePath finalFileName = m_finalFilePath.resolveSymlinks();
|
||||||
|
|
||||||
if constexpr (HostOsInfo::isWindowsHost() && !m_finalFilePath.needsDevice()) {
|
if constexpr (HostOsInfo::isWindowsHost()) {
|
||||||
|
static const bool disableWinSpecialCode = !qEnvironmentVariableIsEmpty(
|
||||||
|
"QTC_DISABLE_SPECIAL_WIN_SAVEFILE");
|
||||||
|
if (!m_finalFilePath.needsDevice() && !disableWinSpecialCode) {
|
||||||
// Release the file lock
|
// Release the file lock
|
||||||
m_tempFile.reset();
|
m_tempFile.reset();
|
||||||
bool result = ReplaceFile(
|
bool result = ReplaceFile(
|
||||||
@@ -153,7 +156,8 @@ bool SaveFile::commit()
|
|||||||
result = MoveFileEx(
|
result = MoveFileEx(
|
||||||
fileName().toStdWString().data(),
|
fileName().toStdWString().data(),
|
||||||
finalFileName.nativePath().toStdWString().data(),
|
finalFileName.nativePath().toStdWString().data(),
|
||||||
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
|
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING
|
||||||
|
| MOVEFILE_WRITE_THROUGH);
|
||||||
if (!result)
|
if (!result)
|
||||||
replaceErrorCode = GetLastError();
|
replaceErrorCode = GetLastError();
|
||||||
}
|
}
|
||||||
@@ -177,7 +181,9 @@ bool SaveFile::commit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const QString backupName = finalFileName.toFSPathString() + '~';
|
const QString backupName = finalFileName.toFSPathString() + '~';
|
||||||
|
|
||||||
// Back up current file.
|
// Back up current file.
|
||||||
@@ -200,8 +206,7 @@ bool SaveFile::commit()
|
|||||||
// return false while keeping the error string from last rename call.
|
// return false while keeping the error string from last rename call.
|
||||||
m_tempFile->filePath().removeFile();
|
m_tempFile->filePath().removeFile();
|
||||||
setErrorString(renameResult.error());
|
setErrorString(renameResult.error());
|
||||||
QFile::rename(
|
QFile::rename(backupName, finalFileName.toFSPathString()); // rollback to backup if possible ...
|
||||||
backupName, finalFileName.toFSPathString()); // rollback to backup if possible ...
|
|
||||||
return false; // ... or keep the backup copy at least
|
return false; // ... or keep the backup copy at least
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +214,6 @@ bool SaveFile::commit()
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void SaveFile::initializeUmask()
|
void SaveFile::initializeUmask()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user