From 92c458b3521909c9db200beb80293a5c64b9b5f8 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Wed, 30 May 2012 11:59:59 +0100 Subject: Fix QFile append on windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. make windows file engine seek to end on open to match unix/symbian 2. make qfile forcibly seek the file engine in case a custom file engine has the same bug. Task-number: QTBUG-25906 Change-Id: I62a26519a9401e547ff77bd8a71027cb361dc671 Reviewed-by: Friedemann Kleint Reviewed-by: Konstantin Ritt Reviewed-by: João Abecasis --- src/corelib/io/qfile.cpp | 7 +++++-- src/corelib/io/qfsfileengine_win.cpp | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index c4bc612..8eea244 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -1036,8 +1036,11 @@ bool QFile::open(OpenMode mode) #endif { QIODevice::open(mode); - if (mode & Append) - seek(size()); + if (mode & Append) { + //The file engine should have done this in open(), + //this is a workaround for backward compatibility + fileEngine()->seek(size()); + } return true; } QFile::FileError err = d->fileEngine->error(); diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 8014720..a148fd9 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -144,6 +144,11 @@ bool QFSFileEnginePrivate::nativeOpen(QIODevice::OpenMode openMode) if (openMode & QIODevice::Truncate) q->setSize(0); + // Seek to the end when in Append mode. + if (openMode & QFile::Append) { + ::SetFilePointer(fileHandle, 0, 0, FILE_END); + } + return true; } -- cgit v0.12