From 4accd865c24b7ed918cb705913478bab5aeb5e6e Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 14 Sep 2015 11:11:54 +0200 Subject: QLockFile: sync to disk to avoid leaving an empty lock file on crash The two lines of code are the same as in QFSFileEnginePrivate::nativeSyncToDisk, but we don't want to create a fileengine instance just for this. qlockfile_win.cpp already calls FlushFileBuffers, only the Unix implementation was missing the equivalent call. Task-number: QTBUG-44771 Change-Id: I2253972857e4de9d27ef442c92983a1088d6f03e Reviewed-by: Thiago Macieira --- src/corelib/io/qlockfile_unix.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index 27f8a97fd4..b298b08939 100644 --- a/src/corelib/io/qlockfile_unix.cpp +++ b/src/corelib/io/qlockfile_unix.cpp @@ -178,6 +178,13 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys() // We hold the lock, continue. fileHandle = fd; + // Sync to disk if possible. Ignore errors (e.g. not supported). +#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0 + fdatasync(fileHandle); +#else + fsync(fileHandle); +#endif + return QLockFile::NoError; } -- cgit v1.2.3