diff --git a/src/libsync/propagateremotemove.cpp b/src/libsync/propagateremotemove.cpp index 1cbc3310b8f61..1290863b6022f 100644 --- a/src/libsync/propagateremotemove.cpp +++ b/src/libsync/propagateremotemove.cpp @@ -243,6 +243,8 @@ void PropagateRemoteMove::slotMoveJobFinished() auto newItem = SyncFileItem::fromSyncJournalFileRecord(rec); newItem->_originalFile = QString(newItem->_file).replace(_item->_renameTarget, _item->_originalFile); newItem->_renameTarget = newItem->_file; + newItem->_instruction = CSYNC_INSTRUCTION_RENAME; + newItem->_direction = SyncFileItem::Up; const auto fsPath = propagator()->fullLocalPath(newItem->_renameTarget); quint64 inode = rec._inode; if (!FileSystem::getInode(fsPath, &inode)) { @@ -257,6 +259,39 @@ void PropagateRemoteMove::slotMoveJobFinished() return; } } + auto &vfs = propagator()->syncOptions()._vfs; + // TODO: vfs->pinState(_item->_originalFile); does not make sense as item is already gone from original location, do we need this? + auto pinState = vfs->pinState(newItem->_originalFile); + const auto targetFile = propagator()->fullLocalPath(newItem->_renameTarget); + + if (QFileInfo::exists(targetFile)) { + // Delete old db data. + if (!propagator()->_journal->deleteFileRecord(_item->_originalFile)) { + qCWarning(lcPropagateRemoteMove) << "could not delete file from local DB" << _item->_originalFile; + done(SyncFileItem::NormalError, + tr("Could not delete file record %1 from local DB").arg(_item->_originalFile), + ErrorCategory::GenericError); + return; + } + // TODO: vfs->setPinState(_item->_originalFile, PinState::Inherited) will always fail as item is already gone from original location, do we + // need this? + if (!vfs->setPinState(_item->_originalFile, PinState::Inherited)) { + qCWarning(lcPropagateRemoteMove) << "Could not set pin state of" << _item->_originalFile << "to inherited"; + } + } + const auto result = propagator()->updateMetadata(*newItem); + 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(newItem->_file), ErrorCategory::GenericError); + return; + } + if (pinState && *pinState != PinState::Inherited && !vfs->setPinState(newItem->_renameTarget, *pinState)) { + done(SyncFileItem::NormalError, tr("Error setting pin state"), ErrorCategory::GenericError); + return; + } + })) { qCWarning(lcPropagateRemoteMove) << "Could not update inode for moved files in" << _item->_renameTarget; }