From db0064b767474a89bc72ea4374f477682983c5f4 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Fri, 24 Feb 2017 15:06:21 -0800 Subject: Speed up QFile::copy on Darwin file systems that support cloning Recent Darwin system have a new system call that allows cloning the contents of a file from another one if the underlying file system (for example, APFS) supports it. Change-Id: I90ec53b8abd2b1dc4000070f295e226d0fb4c672 Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemengine_unix.cpp | 18 ++++++++++++++++++ src/corelib/io/qfsfileengine.cpp | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 40eadfb3e6..31353523ad 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -42,6 +42,7 @@ #include "qfilesystemengine_p.h" #include "qfile.h" +#include #include #include // for realpath() @@ -66,6 +67,9 @@ #endif #if defined(Q_OS_DARWIN) +# if QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(101200, 100000, 100000, 30000) +# include +# endif // We cannot include (it's an Objective-C header), but // we need these declarations: Q_FORWARD_DECLARE_OBJC_CLASS(NSString); @@ -629,8 +633,22 @@ bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSy //static bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error) { +#if QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(101200, 100000, 100000, 30000) + const auto current = QOperatingSystemVersion::current(); + if (current >= QOperatingSystemVersion::MacOSSierra || + current >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 10) || + current >= QOperatingSystemVersion(QOperatingSystemVersion::TvOS, 10) || + current >= QOperatingSystemVersion(QOperatingSystemVersion::WatchOS, 3)) { + 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); +#endif error = QSystemError(ENOSYS, QSystemError::StandardLibraryError); //Function not implemented return false; } diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 0b9cd0557f..de921c0be6 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -860,9 +860,9 @@ bool QFSFileEngine::supportsExtension(Extension extension) const /*! \fn bool QFSFileEngine::copy(const QString ©Name) - For windows, copy the file to file \a copyName. + For Windows or Apple platforms, copy the file to file \a copyName. - Not implemented for Unix. + Not implemented for other Unix platforms. */ /*! \fn QString QFSFileEngine::currentPath(const QString &fileName) -- cgit v1.2.3