Skip to content

Commit

Permalink
Merge pull request #7111 from nextcloud/backport/7102/stable-3.13
Browse files Browse the repository at this point in the history
[stable-3.13] Bugfix/fix one rename issue
  • Loading branch information
mgallien authored Sep 12, 2024
2 parents c7e7492 + 2e0c8d6 commit ab5d509
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ProcessDirectoryJob::ProcessDirectoryJob(const PathTuple &path, const SyncFileIt
, _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 @@ ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinS
, _discoveryData(data)
, _currentFolder(path)
{
qCDebug(lcDisco) << "PREPARING" << _currentFolder._server << _queryServer << _currentFolder._local << _queryLocal;
computePinState(basePinState);
}

Expand Down Expand Up @@ -487,6 +488,7 @@ void ProcessDirectoryJob::processFile(PathTuple path,
<< " | 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 @@ -1678,22 +1680,23 @@ void ProcessDirectoryJob::processFileFinalize(
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 @@ -1251,6 +1251,98 @@ private slots:
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

0 comments on commit ab5d509

Please sign in to comment.