ensure proper VFS metadata when restoring folders
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 30 Apr 2024 11:31:54 +0000 (13:31 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 16 Sep 2024 15:32:53 +0000 (15:32 +0000)
when remote move is forbidden, desktop client will move back the folder
to its original name

in such cases, we were forgetting to set VFS metadata in their proper
state (i.e. placeholder in sync)

so ensure that when a remote move fails, we still touch VFS metadata
when appropriate and handle errors

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/propagateremotemove.cpp

index 401a8f27bf12460d6a3f868a88c8a6e20374f868..6d2c0a229b047fa455859488ae82034edc31ee7e 100644 (file)
@@ -217,7 +217,19 @@ void PropagateRemoteMove::slotMoveJobFinished()
             qCWarning(lcPropagateRemoteMove)
                 << "Could not MOVE file" << filePathOriginal << " to" << filePath
                 << " with error:" << _job->errorString() << " and successfully restored it.";
+
+            auto restoredItem = *_item;
+            restoredItem._renameTarget = _item->_originalFile;
+            const auto result = propagator()->updateMetadata(restoredItem);
+            if (!result) {
+                done(SyncFileItem::FatalError, tr("Error updating metadata: %1").arg(result.error()), ErrorCategory::GenericError);
+                return;
+            } else if (*result == Vfs::ConvertToPlaceholderResult::Locked) {
+                done(SyncFileItem::SoftError, tr("The file %1 is currently in use").arg(restoredItem._file), ErrorCategory::GenericError);
+                return;
+            }
         }
+
         done(status, _job->errorString(), ErrorCategory::GenericError);
         return;
     }