From: Ivailo Monev Date: Thu, 25 Nov 2021 14:00:07 +0000 (+0200) Subject: fix retry code path in QFileSystemEngine::copyFile() for Linux and add disabled LFS... X-Git-Tag: 4.12.0~1519 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f48942cd282020dd8049d4504fbfd3f00651cbb3;p=kde%2FKatie.git fix retry code path in QFileSystemEngine::copyFile() for Linux and add disabled LFS test Signed-off-by: Ivailo Monev --- diff --git a/src/core/io/qfilesystemengine_unix.cpp b/src/core/io/qfilesystemengine_unix.cpp index c02acc5ad..2e36b2975 100644 --- a/src/core/io/qfilesystemengine_unix.cpp +++ b/src/core/io/qfilesystemengine_unix.cpp @@ -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)); diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 43abde6d2..05385d0b9 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -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 -#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(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