diff options
author | David Faure <david.faure@kdab.com> | 2015-09-14 11:11:54 +0200 |
---|---|---|
committer | Albert Astals Cid <albert.astals@canonical.com> | 2015-09-28 09:47:57 +0000 |
commit | 4accd865c24b7ed918cb705913478bab5aeb5e6e (patch) | |
tree | 473155142346a2e6e9e55c49bd9e35ea0417bbb0 /src/corelib/io/qlockfile_unix.cpp | |
parent | b47bcba0f5d0f7f682f46adafe16eebec6eb020b (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qlockfile_unix.cpp')
-rw-r--r-- | src/corelib/io/qlockfile_unix.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
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; } |