diff options
-rw-r--r-- | src/corelib/io/qfile.cpp | 19 | ||||
-rw-r--r-- | src/corelib/io/qresource.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qfile/tst_qfile.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 4 |
4 files changed, 18 insertions, 11 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index 72d1d16..6395cc7 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -968,9 +968,6 @@ bool QFile::isSequential() const mode, if the relevant file does not already exist, this function will try to create a new file before opening it. - \note Because of limitations in the native API, QFile ignores the - Unbuffered flag on Windows. - \sa QIODevice::OpenMode, setFileName() */ bool QFile::open(OpenMode mode) @@ -988,7 +985,9 @@ bool QFile::open(OpenMode mode) qWarning("QIODevice::open: File access not specified"); return false; } - if (fileEngine()->open(mode)) { + + // QIODevice provides the buffering, so there's no need to request it from the file engine. + if (fileEngine()->open(mode | QIODevice::Unbuffered)) { QIODevice::open(mode); if (mode & Append) seek(size()); @@ -1387,11 +1386,17 @@ QFile::close() Q_D(QFile); if(!isOpen()) return; - flush(); + bool flushed = flush(); QIODevice::close(); - unsetError(); - if(!fileEngine()->close()) + // reset write buffer + d->lastWasWrite = false; + d->writeBuffer.clear(); + + // keep earlier error from flush + if (fileEngine()->close() && flushed) + unsetError(); + else if (flushed) d->setError(fileEngine()->error(), fileEngine()->errorString()); } diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 3d54969..adfbb15 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -1285,7 +1285,7 @@ bool QResourceFileEngine::close() bool QResourceFileEngine::flush() { - return false; + return true; } qint64 QResourceFileEngine::read(char *data, qint64 len) diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 453434d..f407b12 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -2119,15 +2119,17 @@ void tst_QFile::fullDisk() file.write(&c, 0); QVERIFY(!file.flush()); QCOMPARE(file.error(), QFile::ResourceError); - file.write(&c, 1); + QCOMPARE(file.write(&c, 1), qint64(1)); QVERIFY(!file.flush()); QCOMPARE(file.error(), QFile::ResourceError); file.close(); QVERIFY(!file.isOpen()); QCOMPARE(file.error(), QFile::ResourceError); + file.open(QIODevice::WriteOnly); QCOMPARE(file.error(), QFile::NoError); + QVERIFY(file.flush()); // Shouldn't inherit write buffer file.close(); QCOMPARE(file.error(), QFile::NoError); diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 8f393fe..20cf922 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -223,7 +223,7 @@ private Q_SLOTS: void ioPostToHttpFromMiddleOfQBufferFiveBytes(); void ioPostToHttpNoBufferFlag(); void ioPostToHttpUploadProgress(); - void ioPostToHttpEmtpyUploadProgress(); + void ioPostToHttpEmptyUploadProgress(); void lastModifiedHeaderForFile(); void lastModifiedHeaderForHttp(); @@ -2921,7 +2921,7 @@ void tst_QNetworkReply::ioPostToHttpUploadProgress() server.close(); } -void tst_QNetworkReply::ioPostToHttpEmtpyUploadProgress() +void tst_QNetworkReply::ioPostToHttpEmptyUploadProgress() { QByteArray ba; ba.resize(0); |