diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-04-20 10:57:20 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-04-23 09:59:43 +0000 |
commit | 6545404afad30b60d1a8e9a2abaf301abaf8f6a5 (patch) | |
tree | d83252e4fa3cbb111171c34500334f047f3e04ee /src/corelib/io/qlockfile_win.cpp | |
parent | 1f2ce78f16a3a8b5d182fbb9c03c373efaa136d8 (diff) |
Windows: Fix QLockFile hanging when file cannot be created.
Return QLockFile::PermissionError when file does not exist, preventing
the stale file detection logic from triggering.
Add Windows-only autotest trying to create a lock file in
a system folder guarded with checks for elevated processes
and UAC virtualization.
Task-number: QTBUG-45631
Change-Id: I1790f8f925660f6bf1df94c2ced901e6ec57cbb0
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
Diffstat (limited to 'src/corelib/io/qlockfile_win.cpp')
-rw-r--r-- | src/corelib/io/qlockfile_win.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/corelib/io/qlockfile_win.cpp b/src/corelib/io/qlockfile_win.cpp index a36e6e93b8..9fe86e1ad8 100644 --- a/src/corelib/io/qlockfile_win.cpp +++ b/src/corelib/io/qlockfile_win.cpp @@ -48,6 +48,12 @@ static inline QByteArray localHostName() return qgetenv("COMPUTERNAME"); } +static inline bool fileExists(const wchar_t *fileName) +{ + WIN32_FILE_ATTRIBUTE_DATA data; + return GetFileAttributesEx(fileName, GetFileExInfoStandard, &data); +} + QLockFile::LockError QLockFilePrivate::tryLock_sys() { const QFileSystemEntry fileEntry(fileName); @@ -79,8 +85,13 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys() case ERROR_SHARING_VIOLATION: case ERROR_ALREADY_EXISTS: case ERROR_FILE_EXISTS: - case ERROR_ACCESS_DENIED: // readonly file, or file still in use by another process. Assume the latter, since we don't create it readonly. return QLockFile::LockFailedError; + case ERROR_ACCESS_DENIED: + // readonly file, or file still in use by another process. + // Assume the latter if the file exists, since we don't create it readonly. + return fileExists((const wchar_t*)fileEntry.nativeFilePath().utf16()) + ? QLockFile::LockFailedError + : QLockFile::PermissionError; default: qWarning() << "Got unexpected locking error" << lastError; return QLockFile::UnknownError; |