From: Christian Kamm Date: Fri, 23 Aug 2019 12:49:24 +0000 (+0200) Subject: PropagateDownload: Don't try to open readonly temporaries X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~191 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3446412d92f5f1527afe392ecb46040d9a9ac8a0;p=nextcloud-desktop.git 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 --- diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 120170382..7ac691df1 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -523,25 +523,27 @@ void PropagateDownloadFile::startDownload() if (tmpFileName.isEmpty()) { tmpFileName = createDownloadTmpFileName(_item->_file); } - _tmpFile.setFileName(propagator()->getFilePath(tmpFileName)); + + _resumeStart = _tmpFile.size(); + if (_resumeStart > 0 && _resumeStart == _item->_size) { + qCInfo(lcPropagateDownload) << "File is already complete, no need to download"; + 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); - _resumeStart = _tmpFile.size(); - if (_resumeStart > 0) { - if (_resumeStart == _item->_size) { - qCInfo(lcPropagateDownload) << "File is already complete, no need to download"; - _tmpFile.close(); - downloadFinished(); - return; - } - } - // If there's not enough space to fully download this file, stop. const auto diskSpaceResult = propagator()->diskSpaceCheck(); if (diskSpaceResult != OwncloudPropagator::DiskSpaceOk) {