Skip to content

Commit a74d10d

Browse files
committed
Use custom rename impl on mac
To prevent `QFile::rename` doing normalization changes to the file name.
1 parent 4c98dec commit a74d10d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/common/filesystembase.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include <io.h>
3636
#endif
3737

38+
#ifdef Q_OS_MAC
39+
#include <CoreServices/CoreServices.h>
40+
#endif
41+
3842
namespace {
3943
// Regarding
4044
// https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
@@ -208,6 +212,17 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName,
208212
{
209213
Q_ASSERT(errorString);
210214
#ifndef Q_OS_WIN
215+
216+
#ifdef Q_OS_MAC
217+
// Don't use QFile::rename, it will normalize the destination filename to NFC
218+
auto src = QFile::encodeName(originFileName);
219+
auto dest = encodeFileName(destinationFileName);
220+
if (::renameatx_np(AT_FDCWD, src.constData(), AT_FDCWD, dest.constData(), 0) != 0) {
221+
*errorString = QString::fromLocal8Bit(strerror(errno));
222+
qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString;
223+
return false;
224+
}
225+
#else
211226
bool success;
212227
QFile orig(originFileName);
213228
// We want a rename that also overwrites. QFile::rename does not overwrite.
@@ -228,6 +243,7 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName,
228243
qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString;
229244
return false;
230245
}
246+
#endif
231247

232248
#else //Q_OS_WIN
233249
// You can not overwrite a read-only file on windows.

0 commit comments

Comments
 (0)