Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8544

QFile::flush() does not actually flush file contents to disk

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.6.2
    • Core: I/O
    • None

    Description

      QFile::flush just calls fflush on a file. This simply moves the data from the c library buffer into the OS buffer, and may or may not depending on c library implementation call the OS flush function. Power loss after calling that function may still lead to data loss - which is especially bad for embedded systems that may randomly loose power.

      On unix systems, the way to correctly flush files to disk is to call fsync(). There is probably a windows equivalent. This is not even called if you open the file with a native file handle - from qfsfileengine_unix.cpp:

      bool QFSFileEnginePrivate::nativeFlush()
      {
      return fh ? flushFh() : fd != -1;
      }

      This is extremely bad - on a unix system with a native file handle, no attempt to flush data is made at all. This is a trivial fix, and some of the pitfalls of flush should at least be described in the docs.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            biochimia João Abecasis
            reuben.dowle Reuben Dowle
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes