Do not close putmultifilejob devices if not open, log when they are not open
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 11 May 2023 13:27:06 +0000 (21:27 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 15 May 2023 12:46:21 +0000 (20:46 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/libsync/putmultifilejob.cpp

index b1d942c8e05e46425d55e6e4022dea7f74516090..67204a2a9c3f299f422372e7f0a01a81e3f1e88a 100644 (file)
@@ -71,15 +71,22 @@ void PutMultiFileJob::start()
 
 bool PutMultiFileJob::finished()
 {
-    for(const auto &oneDevice : _devices) {
-        oneDevice._device->close();
-    }
-
     qCInfo(lcPutMultiFileJob) << "POST of" << reply()->request().url().toString() << path() << "FINISHED WITH STATUS"
                               << replyStatusString()
                               << reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute)
                               << reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute);
 
+    for(const auto &oneDevice : _devices) {
+        Q_ASSERT(oneDevice._device);
+
+        if (oneDevice._device->isOpen()) {
+            oneDevice._device->close();
+        } else {
+            qCWarning(lcPutMultiFileJob) << "Did not close device" << oneDevice._device.get()
+                                         << "as it was not open";
+        }
+    }
+
     emit finishedSignal();
     return true;
 }