Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.14] Bugfix/fix one rename issue #7109

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check notice on line 1 in src/libsync/discovery.cpp

View workflow job for this annotation

GitHub Actions / build

Run clang-format on src/libsync/discovery.cpp

File src/libsync/discovery.cpp does not conform to Custom style guidelines. (lines 536)
* Copyright (C) by Olivier Goffart <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -64,7 +64,7 @@
, _discoveryData(parent->_discoveryData)
, _currentFolder(path)
{
qCDebug(lcDisco) << path._server << queryServer << path._local << queryLocal << lastSyncTimestamp;
qCDebug(lcDisco) << "PREPARING" << _currentFolder._server << _queryServer << _currentFolder._local << _queryLocal;
computePinState(parent->_pinState);
}

Expand All @@ -77,6 +77,7 @@
, _discoveryData(data)
, _currentFolder(path)
{
qCDebug(lcDisco) << "PREPARING" << _currentFolder._server << _queryServer << _currentFolder._local << _queryLocal;
computePinState(basePinState);
}

Expand Down Expand Up @@ -532,6 +533,7 @@
<< " | checksum: " << dbEntry._checksumHeader << "//" << serverEntry.checksumHeader
<< " | perm: " << dbEntry._remotePerm << "//" << serverEntry.remotePerm
<< " | fileid: " << dbEntry._fileId << "//" << serverEntry.fileId
<< " | inode: " << dbEntry._inode << "/" << localEntry.inode << "/"
<< " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile)
<< " | e2ee: " << dbEntry.isE2eEncrypted() << "/" << serverEntry.isE2eEncrypted()
<< " | e2eeMangledName: " << dbEntry.e2eMangledName() << "/" << serverEntry.e2eMangledName
Expand Down Expand Up @@ -1727,22 +1729,23 @@
ASSERT(_dirItem && _dirItem->_instruction == CSYNC_INSTRUCTION_RENAME);
// This is because otherwise subitems are not updated! (ideally renaming a directory could
// update the database for all items! See PropagateDirectory::slotSubJobsFinished)
const auto adjustedOriginalPath = _discoveryData->adjustRenamedPath(path._original, SyncFileItem::Down);
Q_UNUSED(adjustedOriginalPath)
_discoveryData->_renamedItemsLocal.insert(path._original, path._target);
if (_dirItem->_direction == SyncFileItem::Direction::Down) {
_discoveryData->_renamedItemsRemote.insert(path._original, path._target);
} else {
_discoveryData->_renamedItemsLocal.insert(path._original, path._target);
}
item->_instruction = CSYNC_INSTRUCTION_RENAME;
item->_renameTarget = path._target;
item->_direction = _dirItem->_direction;
}

{
const auto discoveredItemLog = QStringLiteral("%1 %2 %3 %4").arg(item->_file).arg(item->_instruction).arg(item->_direction).arg(item->_type);
const auto isImportantInstruction = item->_instruction != CSYNC_INSTRUCTION_NONE && item->_instruction != CSYNC_INSTRUCTION_IGNORE
&& item->_instruction != CSYNC_INSTRUCTION_UPDATE_METADATA;
if (isImportantInstruction) {
qCInfo(lcDisco) << discoveredItemLog;
qCInfo(lcDisco) << "discovered" << item->_file << item->_instruction << item->_direction << item->_type;
} else {
qCDebug(lcDisco) << discoveredItemLog;
qCDebug(lcDisco) << "discovered" << item->_file << item->_instruction << item->_direction << item->_type;
}
}

Expand Down
92 changes: 92 additions & 0 deletions test/testsyncmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
*/

#include <QtTest>

Check failure on line 8 in test/testsyncmove.cpp

View workflow job for this annotation

GitHub Actions / build

test/testsyncmove.cpp:8:10 [clang-diagnostic-error]

'QtTest' file not found
#include "common/result.h"
#include "syncenginetestutils.h"
#include <syncengine.h>
Expand Down Expand Up @@ -1253,6 +1253,98 @@
QCOMPARE(counter.nMOVE, 2);
QCOMPARE(counter.nMKCOL, 0);
}

void testMultipleRenameFromServer()
{
FakeFolder fakeFolder{{}};

fakeFolder.remoteModifier().mkdir("root");
fakeFolder.remoteModifier().mkdir("root/stable");
fakeFolder.remoteModifier().mkdir("root/stable/folder to move");
fakeFolder.remoteModifier().insert("root/stable/folder to move/index.txt");
fakeFolder.remoteModifier().mkdir("root/stable/move");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.remoteModifier().rename("root", "root test");
fakeFolder.remoteModifier().rename("root test/stable/folder to move", "root test/stable/folder");
fakeFolder.remoteModifier().rename("root test/stable/folder", "root test/stable/move/folder");
OperationCounter counter;
fakeFolder.setServerOverride(counter.functor());

connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToPropagate, [&](SyncFileItemVector &items) {
SyncFileItemPtr root, stable, folder, file, move;
for (auto &item : items) {
qDebug() << item->_file;
if (item->_file == "root") {
root = item;
} else if (item->_file == "root test/stable") {
stable = item;
} else if (item->_file == "root test/stable/move") {
move = item;
} else if (item->_file == "root/stable/folder to move") {
folder = item;
} else if (item->_file == "root test/stable/move/folder/index.txt") {
file = item;
}
}

QVERIFY(root);
QCOMPARE(root->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(root->_direction, SyncFileItem::Down);

QVERIFY(stable);
QCOMPARE(stable->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(stable->_direction, SyncFileItem::Down);

QVERIFY(move);
QCOMPARE(move->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(move->_direction, SyncFileItem::Down);

QVERIFY(folder);
QCOMPARE(folder->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(folder->_direction, SyncFileItem::Down);

QVERIFY(file);
QCOMPARE(file->_instruction, CSYNC_INSTRUCTION_RENAME);
QCOMPARE(file->_direction, SyncFileItem::Down);
});

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(counter.nDELETE, 0);
QCOMPARE(counter.nGET, 0);
QCOMPARE(counter.nPUT, 0);
QCOMPARE(counter.nMOVE, 0);
QCOMPARE(counter.nMKCOL, 0);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}

void testMultipleRenameFromLocal()
{
FakeFolder fakeFolder{{}};

fakeFolder.remoteModifier().mkdir("root");
fakeFolder.remoteModifier().mkdir("root/stable");
fakeFolder.remoteModifier().mkdir("root/stable/folder to move");
fakeFolder.remoteModifier().insert("root/stable/folder to move/index.txt");
fakeFolder.remoteModifier().mkdir("root/stable/move");
QVERIFY(fakeFolder.syncOnce());
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());

fakeFolder.localModifier().rename("root", "root test");
fakeFolder.localModifier().rename("root test/stable/folder to move", "root test/stable/folder");
fakeFolder.localModifier().rename("root test/stable/folder", "root test/stable/move/folder");
OperationCounter counter;
fakeFolder.setServerOverride(counter.functor());

QVERIFY(fakeFolder.syncOnce());
QCOMPARE(counter.nDELETE, 0);
QCOMPARE(counter.nGET, 0);
QCOMPARE(counter.nPUT, 0);
QCOMPARE(counter.nMOVE, 2);
QCOMPARE(counter.nMKCOL, 0);
QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
}
};

QTEST_GUILESS_MAIN(TestSyncMove)
Expand Down
Loading