From 26094982f893b6f655d20cefb678b306be02e5ac Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 16 Jul 2017 01:19:23 -0700 Subject: Move the file-cloning code from QFSFileEngine to QFileSystemEngine Change-Id: I02d22222fff64d4dbda4fffd14d1c1bbf48385ff Reviewed-by: Simon Hausmann --- src/corelib/io/qfilesystemengine_unix.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/corelib/io/qfilesystemengine_unix.cpp') diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index d74c126bef..3ba8275dfd 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -78,9 +78,16 @@ extern "C" NSString *NSTemporaryDirectory(); #endif #if defined(Q_OS_LINUX) +# include # include +# include # include +// in case linux/fs.h is too old and doesn't define it: +#ifndef FICLONE +# define FICLONE _IOW(0x94, 9, int) +#endif + # if !QT_CONFIG(renameat2) && defined(SYS_renameat2) static int renameat2(int oldfd, const char *oldpath, int newfd, const char *newpath, unsigned flags) { return syscall(SYS_renameat2, oldfd, oldpath, newfd, newpath, flags); } @@ -1065,6 +1072,19 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM return data.hasFlags(what); } +// static +bool QFileSystemEngine::cloneFile(int srcfd, int dstfd, const QFileSystemMetaData &knownData) +{ +#if defined(Q_OS_LINUX) + // try FICLONE (only works on regular files and only on certain fs) + return ::ioctl(dstfd, FICLONE, srcfd) == 0; +#else + Q_UNUSED(srcfd); + Q_UNUSED(dstfd); + return false; +#endif +} + // Note: if \a shouldMkdirFirst is false, we assume the caller did try to mkdir // before calling this function. static bool createDirectoryWithParents(const QByteArray &nativeName, bool shouldMkdirFirst = true) -- cgit v1.2.3