mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
Fix review comments from Matthieu. Using curent reverse iterator when searching for parent.
Signed-off-by: alex-z <blackslayer4@gmail.com>
This commit is contained in:
parent
37168fce9f
commit
bf80efc7ab
1 changed files with 15 additions and 8 deletions
|
@ -417,15 +417,16 @@ void OwncloudPropagator::adjustDeletedFoldersWithNewChildren(SyncFileItemVector
|
|||
{
|
||||
/*
|
||||
process each item that is new and is a directory and make sure every parent in its tree has the instruction CSYNC_INSTRUCTION_NEW
|
||||
instead of CSYNC_INSTRUCTION_REMOVE
|
||||
instead of CSYNC_INSTRUCTION_REMOVE
|
||||
NOTE: We are iterating backwords to take advantage of optimization later, when searching for the parent of current it
|
||||
*/
|
||||
for (const auto &item : items) {
|
||||
if (item->_instruction != CSYNC_INSTRUCTION_NEW || item->_direction != SyncFileItem::Up || !item->isDirectory() || item->_file == QStringLiteral("/")) {
|
||||
for (auto it = std::crbegin(items); it != std::crend(items); ++it) {
|
||||
if ((*it)->_instruction != CSYNC_INSTRUCTION_NEW || (*it)->_direction != SyncFileItem::Up || !(*it)->isDirectory() || (*it)->_file == QStringLiteral("/")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// #1 get root folder name for the current item that we need to reupload
|
||||
const auto folderPathSplit = item->_file.split(QLatin1Char('/'), Qt::SkipEmptyParts);
|
||||
const auto folderPathSplit = (*it)->_file.split(QLatin1Char('/'), Qt::SkipEmptyParts);
|
||||
if (folderPathSplit.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -434,7 +435,7 @@ void OwncloudPropagator::adjustDeletedFoldersWithNewChildren(SyncFileItemVector
|
|||
continue;
|
||||
}
|
||||
// #2 iterate backwords (for optimization) and find the root folder by name
|
||||
const auto itemRootFolderReverseIt = std::find_if(std::rbegin(items), std::rend(items), [&itemRootFolderName](const auto ¤tItem) {
|
||||
const auto itemRootFolderReverseIt = std::find_if(it, std::crend(items), [&itemRootFolderName](const auto ¤tItem) {
|
||||
return currentItem->_file == itemRootFolderName;
|
||||
});
|
||||
|
||||
|
@ -457,9 +458,9 @@ void OwncloudPropagator::adjustDeletedFoldersWithNewChildren(SyncFileItemVector
|
|||
if ((*nextFolderInTreeIt)->isDirectory()
|
||||
&& (*nextFolderInTreeIt)->_instruction == CSYNC_INSTRUCTION_REMOVE
|
||||
&& (*nextFolderInTreeIt)->_direction == SyncFileItem::Down
|
||||
&& item->_file.startsWith(QString((*nextFolderInTreeIt)->_file) + QLatin1Char('/'))) {
|
||||
&& (*it)->_file.startsWith(QString((*nextFolderInTreeIt)->_file) + QLatin1Char('/'))) {
|
||||
|
||||
qCWarning(lcPropagator) << "WARNING: New directory to upload " << item->_file
|
||||
qCWarning(lcPropagator) << "WARNING: New directory to upload " << (*it)->_file
|
||||
<< "is in the removed directories tree " << (*nextFolderInTreeIt)->_file
|
||||
<< " This should not happen! But, we are going to reupload the entire folder structure.";
|
||||
|
||||
|
@ -467,7 +468,7 @@ void OwncloudPropagator::adjustDeletedFoldersWithNewChildren(SyncFileItemVector
|
|||
(*nextFolderInTreeIt)->_direction = SyncFileItem::Up;
|
||||
}
|
||||
++nextFolderInTreeIt;
|
||||
} while (nextFolderInTreeIt != std::end(items) && (*nextFolderInTreeIt)->_file != item->_file);
|
||||
} while (nextFolderInTreeIt != std::end(items) && (*nextFolderInTreeIt)->_file != (*it)->_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -506,6 +507,12 @@ void OwncloudPropagator::start(SyncFileItemVector &&items)
|
|||
items.end());
|
||||
}
|
||||
|
||||
QStringList files;
|
||||
|
||||
for (const auto &item : items) {
|
||||
files.push_back(item->_file);
|
||||
}
|
||||
|
||||
// process each item that is new and is a directory and make sure every parent in its tree has the instruction NEW instead of REMOVE
|
||||
adjustDeletedFoldersWithNewChildren(items);
|
||||
|
||||
|
|
Loading…
Reference in a new issue