UploadDevice: Fix windows issues #7264
authorChristian Kamm <mail@ckamm.de>
Fri, 21 Jun 2019 09:34:59 +0000 (11:34 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:52 +0000 (10:58 +0100)
- 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.

src/libsync/propagateupload.cpp
src/libsync/propagateupload.h

index 3f3df353eb0d7d8fd0e6f39476dcffdc9f361a1d..f17fc536770483ec39c429dfe3607bc2792728fb 100644 (file)
@@ -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);
index 229a0b222a45eec090e986cffaa2a72f3ac79da9..2d25431714c9936b7ccd746fa44a366b206cdabb 100644 (file)
@@ -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()
     {