From c804715889281b9d8d7a50b928d1823d26dd9f66 Mon Sep 17 00:00:00 2001 From: alex-z Date: Wed, 15 Nov 2023 12:46:43 +0100 Subject: [PATCH] Iteration. Improved move optimization logic. Also account for rename target such that it is the same move. Signed-off-by: alex-z --- src/libsync/owncloudpropagator.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libsync/owncloudpropagator.cpp b/src/libsync/owncloudpropagator.cpp index 09d4d67872d9c..3f1759ceb7a2a 100644 --- a/src/libsync/owncloudpropagator.cpp +++ b/src/libsync/owncloudpropagator.cpp @@ -481,31 +481,31 @@ void OwncloudPropagator::adjustDeletedFoldersWithNewChildren(SyncFileItemVector void OwncloudPropagator::cleanupLocallyMovedFoldersFromNestedItems(SyncFileItemVector &items) { - QString previousFolderPath; - const auto eraseBeginIt = std::remove_if(std::begin(items), std::end(items), [&previousFolderPath](const SyncFileItemPtr &item) { + QString enclosingFolderOriginalPath; + QString enclosingFolderRenamedTargetPath; + const auto eraseBeginIt = std::remove_if(std::begin(items), std::end(items), [&enclosingFolderOriginalPath, &enclosingFolderRenamedTargetPath](const SyncFileItemPtr &item) { // we assume items is always sorted such that parent folder go before children if (item->_instruction != CSYNC_INSTRUCTION_RENAME || item->_direction != SyncFileItem::Up) { - previousFolderPath.clear(); + enclosingFolderOriginalPath.clear(); + enclosingFolderRenamedTargetPath.clear(); return false; } - if (item->isDirectory() && (previousFolderPath.isEmpty() || !item->_originalFile.startsWith(previousFolderPath))) { + if (item->isDirectory() && (enclosingFolderOriginalPath.isEmpty() || enclosingFolderRenamedTargetPath.isEmpty()) + || (!item->_originalFile.startsWith(enclosingFolderOriginalPath) || !item->_renameTarget.startsWith(enclosingFolderRenamedTargetPath))) { // if it is a directory and there was no previous directory set, do it now, same for a directory which is not a child of previous directory, assume // starting a new hierarchy - previousFolderPath = item->_originalFile; + enclosingFolderOriginalPath = item->_originalFile; + enclosingFolderRenamedTargetPath = item->_renameTarget; return false; } - if (previousFolderPath.isEmpty()) { + if (enclosingFolderOriginalPath.isEmpty() || enclosingFolderRenamedTargetPath.isEmpty()) { return false; } - if (item->isDirectory()) { - return false; - } - - // remove only children of previousFolderPath, not previousFolderPath itself such that parent always remains in the vector - return item->_originalFile.startsWith(previousFolderPath); + // remove only children of enclosingFolderOriginalPath, not enclosingFolderOriginalPath itself such that parent always remains in the vector + return item->_originalFile.startsWith(enclosingFolderOriginalPath) && item->_renameTarget.startsWith(enclosingFolderRenamedTargetPath); }); items.erase(eraseBeginIt, std::end(items)); }