Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Nov 16, 2023
1 parent 9662f03 commit 7202274
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,17 +478,13 @@ void OwncloudPropagator::adjustDeletedFoldersWithNewChildren(SyncFileItemVector
} while (nextFolderInTreeIt != std::end(items) && (*nextFolderInTreeIt)->_file != (*it)->_file);
}
}

QString adjustRenamedPathOne(QMap<QString, QString> &renamedDirectoriesIn, const QString &original)
{
return OCC::adjustRenamedPath(renamedDirectoriesIn, original);
}

void OwncloudPropagator::cleanupLocallyMovedFoldersFromNestedItems(SyncFileItemVector &items)
{

// TODO: this methid is not the fastest we could do, but, for now it works, maybe add a flag "_isAnyMultipleRenameUploads" in discovery
// so this could be skipped if no moves discovered?
QMap<QString, QString> renamedDirectories;
for (const auto &item : items) {
// TODO: for now, let's only process uploads (for downloads, we need to also adjust PropagateLocalRename such that correct DB records and pin states are set)
if (item->isDirectory() && item->_instruction == CSYNC_INSTRUCTION_RENAME && item->_instruction == SyncFileItem::Up) {
renamedDirectories.insert(item->_file, item->_renameTarget);
}
Expand All @@ -498,11 +494,10 @@ void OwncloudPropagator::cleanupLocallyMovedFoldersFromNestedItems(SyncFileItemV
return;
}

QString enclosingFolderOriginalPath;
QString enclosingFolderRenamedTargetPath;
// get rid of nested items that are inside already moved folders such that we only run one move job (for parent, and just update children in DB during sync)
const auto eraseBeginIt = std::remove_if(std::begin(items), std::end(items), [&renamedDirectories](const SyncFileItemPtr &item) {
QString origin = adjustRenamedPathOne(renamedDirectories, item->_file);
return origin == item->_renameTarget;
const auto origin = staticAdjustRenamedPath(renamedDirectories, item->_file);
return origin == item->_renameTarget;
});
items.erase(eraseBeginIt, std::end(items));
}
Expand Down Expand Up @@ -1055,7 +1050,7 @@ OCC::Optional<QString> OwncloudPropagator::createCaseClashConflict(const SyncFil

QString OwncloudPropagator::adjustRenamedPath(const QString &original) const
{
return OCC::adjustRenamedPath(_renamedDirectories, original);
return staticAdjustRenamedPath(_renamedDirectories, original);
}

Result<Vfs::ConvertToPlaceholderResult, QString> OwncloudPropagator::updateMetadata(const SyncFileItem &item)
Expand All @@ -1081,6 +1076,11 @@ Result<Vfs::ConvertToPlaceholderResult, QString> OwncloudPropagator::staticUpdat
return Vfs::ConvertToPlaceholderResult::Ok;
}

QString OwncloudPropagator::staticAdjustRenamedPath(const QMap<QString, QString> &renamedDirectories, const QString &original)
{
return OCC::adjustRenamedPath(renamedDirectories, original);
}

bool OwncloudPropagator::isDelayedUploadItem(const SyncFileItemPtr &item) const
{
const auto checkFileShouldBeEncrypted = [this] (const SyncFileItemPtr &item) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/owncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ class OWNCLOUDSYNC_EXPORT OwncloudPropagator : public QObject
static Result<Vfs::ConvertToPlaceholderResult, QString> staticUpdateMetadata(const SyncFileItem &item, const QString localDir,
Vfs *vfs, SyncJournalDb * const journal);

static QString staticAdjustRenamedPath(const QMap<QString, QString> &renamedDirectories, const QString &original);

Q_REQUIRED_RESULT bool isDelayedUploadItem(const SyncFileItemPtr &item) const;

Q_REQUIRED_RESULT const std::deque<SyncFileItemPtr>& delayedTasks() const
Expand Down

0 comments on commit 7202274

Please sign in to comment.