QLockFile: Avoid zero-sized lock file on write error

Failure to write into a successfully opened lock file left the
lock file with size 0 in the filesystem.

Task-number: QTBUG-44771
Change-Id: I561bf629b9f160174d658bf105be828f71d78ff9
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
hjk 2015-03-03 11:11:08 +01:00
parent b35c389b6a
commit dd06d03661

View File

@ -157,13 +157,17 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys()
if (!setNativeLocks(fd))
qWarning() << "setNativeLocks failed:" << strerror(errno);
if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) {
close(fd);
if (!QFile::remove(fileName))
qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName));
return QLockFile::UnknownError; // partition full
}
// We hold the lock, continue.
fileHandle = fd;
QLockFile::LockError error = QLockFile::NoError;
if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size())
error = QLockFile::UnknownError; // partition full
return error;
return QLockFile::NoError;
}
bool QLockFilePrivate::removeStaleLock()