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 <thiago.macieira@intel.com>
This commit is contained in:
parent
be74da81df
commit
db0064b767
@ -42,6 +42,7 @@
|
|||||||
#include "qfilesystemengine_p.h"
|
#include "qfilesystemengine_p.h"
|
||||||
#include "qfile.h"
|
#include "qfile.h"
|
||||||
|
|
||||||
|
#include <QtCore/qoperatingsystemversion.h>
|
||||||
#include <QtCore/qvarlengtharray.h>
|
#include <QtCore/qvarlengtharray.h>
|
||||||
|
|
||||||
#include <stdlib.h> // for realpath()
|
#include <stdlib.h> // for realpath()
|
||||||
@ -66,6 +67,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(Q_OS_DARWIN)
|
#if defined(Q_OS_DARWIN)
|
||||||
|
# if QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(101200, 100000, 100000, 30000)
|
||||||
|
# include <sys/clonefile.h>
|
||||||
|
# endif
|
||||||
// We cannot include <Foundation/Foundation.h> (it's an Objective-C header), but
|
// We cannot include <Foundation/Foundation.h> (it's an Objective-C header), but
|
||||||
// we need these declarations:
|
// we need these declarations:
|
||||||
Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
|
Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
|
||||||
@ -629,8 +633,22 @@ bool QFileSystemEngine::createLink(const QFileSystemEntry &source, const QFileSy
|
|||||||
//static
|
//static
|
||||||
bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
|
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(source);
|
||||||
Q_UNUSED(target);
|
Q_UNUSED(target);
|
||||||
|
#endif
|
||||||
error = QSystemError(ENOSYS, QSystemError::StandardLibraryError); //Function not implemented
|
error = QSystemError(ENOSYS, QSystemError::StandardLibraryError); //Function not implemented
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -860,9 +860,9 @@ bool QFSFileEngine::supportsExtension(Extension extension) const
|
|||||||
|
|
||||||
/*! \fn bool QFSFileEngine::copy(const QString ©Name)
|
/*! \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)
|
/*! \fn QString QFSFileEngine::currentPath(const QString &fileName)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user