diff options
author | David Faure <david.faure@kdab.com> | 2014-09-04 16:29:25 +0200 |
---|---|---|
committer | David Faure <david.faure@kdab.com> | 2014-09-11 00:17:33 +0200 |
commit | 7b9f7f3891230ddd2b2ef5cf3c760a605a02ee96 (patch) | |
tree | fb4ff47e82c6c24371a88fff04db1b256d1351b0 /src/corelib/io/qlockfile_unix.cpp | |
parent | 92404c9cdb195b0ce161b6d096711def9162745d (diff) |
QLockFile: on Windows, retry deleting the lock file if it is being read.
A "sharing violation" happens when trying to delete the lock file and another
thread/process is reading it at that very moment. Detect the error and try again,
up to 10000 times - to avoid an infinite loop if QFile::remove fails for another
reason such as a sudden change of permissions preventing us from deleting our
own lock file.
On Unix the deletion can't fail because of readers, but it doesn't hurt
to check the return value there too, to catch other reasons for failures
such as a sudden permission change.
Task-number: QTBUG-38853
Change-Id: Icf12a74faed4a4916e3427abc09d9c33aa141476
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 | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index d1ef9c1770..cd4cf3a50d 100644 --- a/src/corelib/io/qlockfile_unix.cpp +++ b/src/corelib/io/qlockfile_unix.cpp @@ -206,7 +206,10 @@ void QLockFile::unlock() return; close(d->fileHandle); d->fileHandle = -1; - QFile::remove(d->fileName); + if (!QFile::remove(d->fileName)) { + qWarning() << "Could not remove our own lock file" << d->fileName << "maybe permissions changed meanwhile?"; + // This is bad because other users of this lock file will now have to wait for the stale-lock-timeout... + } d->lockError = QLockFile::NoError; d->isLocked = false; } |