From c4eacb70fdef6da6ca6793cf98600d0711361503 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 24 Jan 2025 12:36:58 -0800 Subject: [PATCH] QFileSystemEngine/Darwin: remove use of clonefile() on Apple systems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because we called this before opening the target file, we did not check that the destination file engine is the QFSFileEngine, and therefore we may have passed a path that referred to a Qt resource path. We still do that on Windows, but Qt resource paths start with a ':' character and that is not allowed on Windows, so the Win32 CopyFile() function fails. Moreover, this function *can* clone directory trees, which we don't want to happen because it doesn't happen on other OSes. Instead, fall back to the fcopyfile() call in cloneFile(). It will still do cloning where permitted. This was added in commit db0064b767474a89bc72ea4374f477682983c5f4, before the fcopyfile() in 974b3adf8a099ca95fc2eabfc434038ce73f62c8, though both were for Qt 5.10. [ChangeLog][QtCore][QFile] Fixed a bug on Apple systems that would cause copy() to copy a directory if the QFile pointed to a directory and the destination was in the same volume. Now copy()'s behavior is the same as in other OSes: directories are never copied. [ChangeLog][QtCore][QFile] Fixed a bug on Apple systems that allowed copy() to create a file with the name that referred to a Qt resource path, if one tried to copy to that path. Qt resource paths can't be modified using QFile. Change-Id: I996368f4c656ff10ff5efffd5b47c6ddde34fd10 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 45886e6a81016c5c9212fffb5c0a83fd2431223e) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qfilesystemengine_unix.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 530b03d60dc..f4dee68d528 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -47,7 +47,6 @@ # include # include # include -# include # include #endif @@ -1617,18 +1616,10 @@ bool QFileSystemEngine::moveFileToTrash(const QFileSystemEntry &source, //static bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { -#if defined(Q_OS_DARWIN) - if (::clonefile(source.nativeFilePath().constData(), - target.nativeFilePath().constData(), 0) == 0) - return true; - error = QSystemError(errno, QSystemError::StandardLibraryError); - return false; -#else Q_UNUSED(source); Q_UNUSED(target); error = QSystemError(ENOSYS, QSystemError::StandardLibraryError); //Function not implemented return false; -#endif } //static