Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
4.6.2
-
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.