PropagateDownload: Don't try to open readonly temporaries

This situation could arrise when receiving a read-only share and the
temporary rename failed for some reason.

See #7419
This commit is contained in:
Christian Kamm 2019-08-23 14:49:24 +02:00 committed by Kevin Ottens
parent f78c4f851b
commit 3446412d92
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2

View file

@ -523,24 +523,26 @@ void PropagateDownloadFile::startDownload()
if (tmpFileName.isEmpty()) {
tmpFileName = createDownloadTmpFileName(_item->_file);
}
_tmpFile.setFileName(propagator()->getFilePath(tmpFileName));
if (!_tmpFile.open(QIODevice::Append | QIODevice::Unbuffered)) {
done(SyncFileItem::NormalError, _tmpFile.errorString());
_resumeStart = _tmpFile.size();
if (_resumeStart > 0 && _resumeStart == _item->_size) {
qCInfo(lcPropagateDownload) << "File is already complete, no need to download";
downloadFinished();
return;
}
FileSystem::setFileHidden(_tmpFile.fileName(), true);
_resumeStart = _tmpFile.size();
if (_resumeStart > 0) {
if (_resumeStart == _item->_size) {
qCInfo(lcPropagateDownload) << "File is already complete, no need to download";
_tmpFile.close();
downloadFinished();
return;
}
// Can't open(Append) read-only files, make sure to make
// file writable if it exists.
if (_tmpFile.exists())
FileSystem::setFileReadOnly(_tmpFile.fileName(), false);
if (!_tmpFile.open(QIODevice::Append | QIODevice::Unbuffered)) {
qCWarning(lcPropagateDownload) << "could not open temporary file" << _tmpFile.fileName();
done(SyncFileItem::NormalError, _tmpFile.errorString());
return;
}
// Hide temporary after creation
FileSystem::setFileHidden(_tmpFile.fileName(), true);
// If there's not enough space to fully download this file, stop.
const auto diskSpaceResult = propagator()->diskSpaceCheck();