OSDN Git Service

fix retry code path in QFileSystemEngine::copyFile() for Linux and add disabled LFS...
authorIvailo Monev <xakepa10@gmail.com>
Thu, 25 Nov 2021 14:00:07 +0000 (16:00 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Thu, 25 Nov 2021 14:00:07 +0000 (16:00 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/io/qfilesystemengine_unix.cpp
tests/auto/qfile/tst_qfile.cpp

index c02acc5..2e36b29 100644 (file)
@@ -326,21 +326,19 @@ bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSyst
     }
 
     QT_OFF_T tocopy = st.st_size;
+    QT_OFF_T totalwrite = 0;
 #ifdef Q_OS_LINUX
-    ssize_t sendresult = ::sendfile(targetfd, sourcefd, nullptr, tocopy);
-    while (sendresult != tocopy) {
+    while (totalwrite != tocopy) {
+        // sendfile64() may use internal types (different from off_t), do not use it
+        const ssize_t sendresult = ::sendfile(targetfd, sourcefd, &totalwrite, tocopy - totalwrite);
         if (sendresult == -1) {
             *error = errno;
             qt_safe_close(sourcefd);
             qt_safe_close(targetfd);
             return false;
         }
-        tocopy -= sendresult;
-        // sendfile64() may use internal types (different from off_t), do not use it
-        sendresult = ::sendfile(targetfd, sourcefd, &tocopy, tocopy);
     }
 #else
-    QT_OFF_T totalwrite = 0;
     QSTACKARRAY(char, copybuffer, QT_BUFFSIZE);
     while (totalwrite != tocopy) {
         const qint64 readresult = qt_safe_read(sourcefd, copybuffer, sizeof(copybuffer));
index 43abde6..05385d0 100644 (file)
@@ -42,6 +42,8 @@
 #  include "../network-settings.h"
 #endif
 
+// #define TEST_LFS
+
 Q_DECLARE_METATYPE(QFile::FileError)
 
 //TESTED_CLASS=
@@ -108,7 +110,9 @@ private slots:
     void readTextFile2();
     void writeTextFile_data();
     void writeTextFile();
-    /* void largeFileSupport(); */
+#ifdef TEST_LFS
+    void largeFileSupport();
+#endif
     void tailFile();
     void flush();
     void bufferedRead();
@@ -1595,61 +1599,25 @@ void tst_QFile::FILEReadWrite()
 }
 
 
-/*
-#include <qglobal.h>
-#define BUFFSIZE 1
-#define FILESIZE   0x10000000f
+#ifdef TEST_LFS
 void tst_QFile::largeFileSupport()
 {
-#ifdef Q_OS_SOLARIS
-    QSKIP("Solaris does not support statfs", SkipAll);
-#else
-    qlonglong sizeNeeded = 2147483647;
-    sizeNeeded *= 2;
-    sizeNeeded += 1024;
-    qlonglong freespace = qlonglong(0);
-    struct statfs info;
-    if (statfs(const_cast<char *>(QDir::currentPath().toLocal8Bit().constData()), &info) == 0) {
-        freespace = qlonglong(info.f_bavail * info.f_bsize);
-        if (freespace > sizeNeeded) {
-            QFile bigFile("bigfile");
-            if (bigFile.open(QFile::ReadWrite)) {
-                char c[BUFFSIZE] = {'a'};
-                QVERIFY(bigFile.write(c, BUFFSIZE) == BUFFSIZE);
-                qlonglong oldPos = bigFile.pos();
-                QVERIFY(bigFile.resize(sizeNeeded));
-                QCOMPARE(oldPos, bigFile.pos());
-                QVERIFY(bigFile.seek(sizeNeeded - BUFFSIZE));
-                QVERIFY(bigFile.write(c, BUFFSIZE) == BUFFSIZE);
-
-                bigFile.close();
-                if (bigFile.open(QFile::ReadOnly)) {
-                    QVERIFY(bigFile.read(c, BUFFSIZE) == BUFFSIZE);
-                    int i = 0;
-                    for (i=0; i<BUFFSIZE; i++)
-                        QCOMPARE(c[i], 'a');
-                    QVERIFY(bigFile.seek(sizeNeeded - BUFFSIZE));
-                    QVERIFY(bigFile.read(c, BUFFSIZE) == BUFFSIZE);
-                    for (i=0; i<BUFFSIZE; i++)
-                        QCOMPARE(c[i], 'a');
-                    bigFile.close();
-                    QVERIFY(bigFile.remove());
-                } else {
-                    QVERIFY(bigFile.remove());
-                    QFAIL("Could not reopen file");
-                }
-            } else {
-                QFAIL("Could not open file");
-            }
-        } else {
-            QSKIP("Not enough space to run test", SkipSingle);
-        }
-    } else {
-        QFAIL("Could not determin disk space");
-    }
-#endif
+    static const QString largefilesrc(QDir::currentPath() + "/largefilesrc.txt");
+    static const QString largefilerename(QDir::currentPath() + "/largefilerename.txt");
+    static const QString largefilecopy(QDir::currentPath() + "/largefilecopy.txt");
+
+    QFile largefile(largefilesrc);
+    QVERIFY(largefile.open(QIODevice::Truncate | QIODevice::ReadWrite));
+    QVERIFY(largefile.write("foo"));
+    QVERIFY(largefile.resize(4000000000));
+    largefile.close();
+
+    QVERIFY(QFile::rename(largefilesrc, largefilerename));
+    QVERIFY(QFile::copy(largefilerename, largefilecopy));
+    QVERIFY(QFile::remove(largefilerename));
+    QVERIFY(QFile::remove(largefilecopy));
 }
-*/
+#endif // TEST_LFS
 
 void tst_QFile::i18nFileName_data()
 {