diff options
-rw-r--r-- | src/corelib/io/qabstractfileengine.cpp | 13 | ||||
-rw-r--r-- | src/corelib/io/qabstractfileengine_p.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine.cpp | 11 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_p.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 17 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine_win.cpp | 18 |
6 files changed, 58 insertions, 4 deletions
diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp index b12dc47c52..e046119fe2 100644 --- a/src/corelib/io/qabstractfileengine.cpp +++ b/src/corelib/io/qabstractfileengine.cpp @@ -400,6 +400,19 @@ bool QAbstractFileEngine::close() } /*! + \since 5.1 + + Flushes and syncs the file to disk. + + Returns true if successful; otherwise returns false. + The default implementation always returns false. +*/ +bool QAbstractFileEngine::syncToDisk() +{ + return false; +} + +/*! Flushes the open file, returning true if successful; otherwise returns false. diff --git a/src/corelib/io/qabstractfileengine_p.h b/src/corelib/io/qabstractfileengine_p.h index 2cbd927968..5106c01be9 100644 --- a/src/corelib/io/qabstractfileengine_p.h +++ b/src/corelib/io/qabstractfileengine_p.h @@ -124,6 +124,7 @@ public: virtual bool open(QIODevice::OpenMode openMode); virtual bool close(); virtual bool flush(); + virtual bool syncToDisk(); virtual qint64 size() const; virtual qint64 pos() const; virtual bool seek(qint64 pos); diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 1bc3a7da2e..11cbda14ca 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -419,6 +419,17 @@ bool QFSFileEngine::flush() } /*! + \reimp +*/ +bool QFSFileEngine::syncToDisk() +{ + Q_D(QFSFileEngine); + if ((d->openMode & QIODevice::WriteOnly) == 0) + return true; + return d->nativeSyncToDisk(); +} + +/*! \internal */ bool QFSFileEnginePrivate::flushFh() diff --git a/src/corelib/io/qfsfileengine_p.h b/src/corelib/io/qfsfileengine_p.h index cf70032134..5d3a6a3767 100644 --- a/src/corelib/io/qfsfileengine_p.h +++ b/src/corelib/io/qfsfileengine_p.h @@ -81,6 +81,7 @@ public: bool open(QIODevice::OpenMode flags, FILE *fh); bool close(); bool flush(); + bool syncToDisk(); qint64 size() const; qint64 pos() const; bool seek(qint64); @@ -150,6 +151,7 @@ public: bool nativeClose(); bool closeFdFh(); bool nativeFlush(); + bool nativeSyncToDisk(); bool flushFh(); qint64 nativeSize() const; #ifndef Q_OS_WIN diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index 8f622d77cd..05b55525b6 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -258,6 +258,23 @@ bool QFSFileEnginePrivate::nativeFlush() /*! \internal + \since 5.1 +*/ +bool QFSFileEnginePrivate::nativeSyncToDisk() +{ + Q_Q(QFSFileEngine); +#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 + const int ret = fdatasync(nativeHandle()); +#else + const int ret = fsync(nativeHandle()); +#endif + if (ret != 0) + q->setError(QFile::WriteError, qt_error_string(errno)); + return ret == 0; +} + +/*! + \internal */ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 len) { diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 86e9bf971d..756e884bd1 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -198,15 +198,25 @@ bool QFSFileEnginePrivate::nativeFlush() return true; } - // Windows native mode; flushing is - // unnecessary. FlushFileBuffers(), the equivalent of sync() or - // fsync() on Unix, does a low-level flush to the disk, and we - // don't expose an API for this. + // Windows native mode; flushing is unnecessary. return true; } /* \internal + \since 5.1 +*/ +bool QFSFileEnginePrivate::nativeSyncToDisk() +{ + if (fh || fd != -1) { + // stdlib / stdio mode. No API available. + return false; + } + return FlushFileBuffers(fileHandle); +} + +/* + \internal */ qint64 QFSFileEnginePrivate::nativeSize() const { |