Skip to content

Commit

Permalink
Give a proper name to a parent path update metho in SyncJournal.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Jan 10, 2024
1 parent e2d38a9 commit 147c170
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/common/syncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ Result<void, QString> SyncJournalDb::setFileRecord(const SyncJournalFileRecord &
return {};
}

bool SyncJournalDb::updateParentForAllChildren(const QByteArray &oldParentPath, const QByteArray &newParentPath)
bool SyncJournalDb::relocateFolderToNewPathRecursively(const QByteArray &oldParentPath, const QByteArray &newParentPath)
{
qCInfo(lcDb) << "Moving files from path" << oldParentPath << "to path" << newParentPath;

Expand Down
4 changes: 3 additions & 1 deletion src/common/syncjournaldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
[[nodiscard]] bool getFilesBelowPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord&)> &rowCallback);
[[nodiscard]] bool listFilesInPath(const QByteArray &path, const std::function<void(const SyncJournalFileRecord&)> &rowCallback);
[[nodiscard]] Result<void, QString> setFileRecord(const SyncJournalFileRecord &record);
[[nodiscard]] bool updateParentForAllChildren(const QByteArray &oldParentPath, const QByteArray &newParentPath);
// use this after moving a folder and all its contents under new parent (e.g. "folderA" move to "parentFolder", such that "folderA" -> "parentFolder/folderA"
// all nested items will have their paths updated accordingly wiht a single UPDATE query
[[nodiscard]] bool relocateFolderToNewPathRecursively(const QByteArray &oldParentPath, const QByteArray &newParentPath);

void keyValueStoreSet(const QString &key, QVariant value);
[[nodiscard]] qint64 keyValueStoreGetInt(const QString &key, qint64 defaultValue);
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateremotemove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void PropagateRemoteMove::finalize()
}

if (_item->isDirectory()) {
if (!propagator()->_journal->updateParentForAllChildren(origin.toUtf8(), _item->_renameTarget.toUtf8())) {
if (!propagator()->_journal->relocateFolderToNewPathRecursively(origin.toUtf8(), _item->_renameTarget.toUtf8())) {
done(SyncFileItem::FatalError, tr("Failed to move folder: %1").arg(_item->_file), ErrorCategory::GenericError);
return;
}
Expand Down
5 changes: 2 additions & 3 deletions test/testsyncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,8 @@ private slots:
QVERIFY(makeEntry(folder2ContentsMoved.first().first, folder2ContentsMoved.first().second, initialEtag));

// move a folder under new location, all children paths must get updated with one query
QVERIFY(_db.updateParentForAllChildren(folder1Contents.first().first, folder1ContentsMoved.first().first));
QVERIFY(_db.updateParentForAllChildren(folder2Contents.first().first, folder2ContentsMoved.first().first));

QVERIFY(_db.relocateFolderToNewPathRecursively(folder1Contents.first().first, folder1ContentsMoved.first().first));
QVERIFY(_db.relocateFolderToNewPathRecursively(folder2Contents.first().first, folder2ContentsMoved.first().first));
// verify all moved records exist under new paths
for (const auto &folderItemMoved : folder1ContentsMoved) {
SyncJournalFileRecord movedRecord;
Expand Down

0 comments on commit 147c170

Please sign in to comment.