Skip to content

Commit

Permalink
Use custom rename impl on mac
Browse files Browse the repository at this point in the history
To prevent `QFile::rename` doing normalization changes to the file name.
  • Loading branch information
erikjv authored and DeepDiver1975 committed Jan 27, 2025
1 parent 46a4dda commit ebc8116
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <io.h>
#endif

#ifdef Q_OS_MAC
#include <CoreServices/CoreServices.h>
#endif

namespace {
// Regarding
// https://en.wikipedia.org/wiki/Comparison_of_file_systems#Limits
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit ebc8116

Please sign in to comment.