From: Christian Kamm Date: Fri, 21 Jun 2019 09:34:59 +0000 (+0200) Subject: UploadDevice: Fix windows issues #7264 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~226 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=69fa1e4775bc3893f73e5193dcbdb7851e3d40f4;p=nextcloud-desktop.git UploadDevice: Fix windows issues #7264 - Close the UploadDevice to close the QFile after the PUT job is done. This allows winvfs to get an oplock on the file later. - Don't rely on QFile::fileName() to be valid after openAndSeekFileSharedRead() was called. The way it is openend on Windows makes it have an empty filename. --- diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 3f3df353e..f17fc5367 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -97,6 +97,19 @@ void PUTFileJob::start() AbstractNetworkJob::start(); } +bool PUTFileJob::finished() +{ + _device->close(); + + qCInfo(lcPutJob) << "PUT of" << reply()->request().url().toString() << "FINISHED WITH STATUS" + << replyStatusString() + << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute) + << reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute); + + emit finishedSignal(); + return true; +} + void PollJob::start() { setTimeout(120 * 1000); @@ -470,13 +483,17 @@ bool UploadDevice::open(QIODevice::OpenMode mode) if (mode & QIODevice::WriteOnly) return false; + // Get the file size now: _file.fileName() is no longer reliable + // on all platforms after openAndSeekFileSharedRead(). + auto fileDiskSize = FileSystem::getSize(_file.fileName()); + QString openError; if (!FileSystem::openAndSeekFileSharedRead(&_file, &openError, _start)) { setErrorString(openError); return false; } - _size = qBound(0ll, _size, FileSystem::getSize(_file.fileName()) - _start); + _size = qBound(0ll, _size, fileDiskSize - _start); _read = 0; return QIODevice::open(mode); diff --git a/src/libsync/propagateupload.h b/src/libsync/propagateupload.h index 229a0b222..2d2543171 100644 --- a/src/libsync/propagateupload.h +++ b/src/libsync/propagateupload.h @@ -122,16 +122,7 @@ public: void start() override; - bool finished() override - { - qCInfo(lcPutJob) << "PUT of" << reply()->request().url().toString() << "FINISHED WITH STATUS" - << replyStatusString() - << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute) - << reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute); - - emit finishedSignal(); - return true; - } + bool finished() override; QIODevice *device() {