From 0446760d558924ea003f10bf5a6bed8ae2876a40 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 24 Jan 2025 14:18:04 +0100 Subject: [PATCH] Use custom rename impl on mac To prevent `QFile::rename` doing normalization changes to the file name. --- src/common/filesystembase.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index c4057a0ffff..5ae7616511d 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -35,6 +35,10 @@ #include #endif +#ifdef Q_OS_MAC +#include +#endif + namespace { // Regarding // https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits @@ -208,6 +212,17 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName, { Q_ASSERT(errorString); #ifndef Q_OS_WIN + +#ifdef Q_OS_MAC + // Don't use QFile::rename, it will normalize the destination filename to NFC + auto src = QFile::encodeName(originFileName); + auto dest = encodeFileName(destinationFileName); + if (::renameatx_np(AT_FDCWD, src.constData(), AT_FDCWD, dest.constData(), 0) != 0) { + *errorString = QString::fromLocal8Bit(strerror(errno)); + qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString; + return false; + } +#else bool success; QFile orig(originFileName); // We want a rename that also overwrites. QFile::rename does not overwrite. @@ -228,6 +243,7 @@ bool FileSystem::uncheckedRenameReplace(const QString &originFileName, qCWarning(lcFileSystem) << "Renaming temp file to final failed: " << *errorString; return false; } +#endif #else //Q_OS_WIN // You can not overwrite a read-only file on windows.