summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemengine_unix.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-07-16 01:19:23 -0700
committerSimon Hausmann <simon.hausmann@qt.io>2017-08-22 06:56:08 +0000
commit26094982f893b6f655d20cefb678b306be02e5ac (patch)
treebcf7cce4bdd6fbc5eb991dd227d0f5945e64af7d /src/corelib/io/qfilesystemengine_unix.cpp
parent750a252b89e62a7325a6d0c0c470f2c6781ad875 (diff)
Move the file-cloning code from QFSFileEngine to QFileSystemEngine
Change-Id: I02d22222fff64d4dbda4fffd14d1c1bbf48385ff Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/io/qfilesystemengine_unix.cpp')
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp20
1 files changed, 20 insertions, 0 deletions
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 <sys/ioctl.h>
# include <sys/syscall.h>
+# include <sys/sendfile.h>
# include <linux/fs.h>
+// 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)