From 976dbd6df6099f12d8f8cd6d1b8b8190351dad1c Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 19 Feb 2024 14:46:52 +0100 Subject: [PATCH] when moving a file, checks that it exists at origin or destination current automated tests are never breaking the rule that a file that should be moved on client side (after a move was done server side) exists either at teh original path or the destination path. in practice it may happen (and I manually tested it) thet the sync engine decides to move a single file in two distinct places that decision will violate this rule and a debug build would then run into the assert Close #6462 Signed-off-by: Matthieu Gallien --- src/libsync/propagatorjobs.cpp | 5 +++-- test/testsyncmove.cpp | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp index 9749f5a1d0b79..82167f5b9c817 100644 --- a/src/libsync/propagatorjobs.cpp +++ b/src/libsync/propagatorjobs.cpp @@ -224,10 +224,10 @@ void PropagateLocalRename::start() auto &vfs = propagator()->syncOptions()._vfs; const auto previousNameInDb = propagator()->adjustRenamedPath(_item->_file); - const auto existingFile = propagator()->fullLocalPath(propagator()->adjustRenamedPath(_item->_file)); + const auto existingFile = propagator()->fullLocalPath(previousNameInDb); const auto targetFile = propagator()->fullLocalPath(_item->_renameTarget); - const auto fileAlreadyMoved = !QFileInfo::exists(propagator()->fullLocalPath(_item->_originalFile)); + const auto fileAlreadyMoved = !QFileInfo::exists(propagator()->fullLocalPath(_item->_originalFile)) && QFileInfo::exists(existingFile); auto pinState = OCC::PinState::Unspecified; if (!fileAlreadyMoved) { auto pinStateResult = vfs->pinState(propagator()->adjustRenamedPath(_item->_file)); @@ -239,6 +239,7 @@ void PropagateLocalRename::start() // if the file is a file underneath a moved dir, the _item->file is equal // to _item->renameTarget and the file is not moved as a result. qCDebug(lcPropagateLocalRename) << _item->_file << _item->_renameTarget << _item->_originalFile << previousNameInDb << (fileAlreadyMoved ? "original file has already moved" : "original file is still there"); + Q_ASSERT(QFileInfo::exists(propagator()->fullLocalPath(_item->_originalFile)) || QFileInfo::exists(existingFile)); if (_item->_file != _item->_renameTarget) { propagator()->reportProgress(*_item, 0); qCDebug(lcPropagateLocalRename) << "MOVE " << existingFile << " => " << targetFile; diff --git a/test/testsyncmove.cpp b/test/testsyncmove.cpp index 04f29f8bebf96..8ad19815524ca 100644 --- a/test/testsyncmove.cpp +++ b/test/testsyncmove.cpp @@ -84,6 +84,12 @@ class TestSyncMove : public QObject Q_OBJECT private slots: + void initTestCase() + { + Logger::instance()->setLogFlush(true); + Logger::instance()->setLogDebug(true); + } + void testMoveCustomRemoteRoot() { FileInfo subFolder(QStringLiteral("AS"), { { QStringLiteral("f1"), 4 } }); @@ -140,7 +146,22 @@ private slots: void testSelectiveSyncMovedFolder() { // issue #5224 - FakeFolder fakeFolder{ FileInfo{ QString(), { FileInfo{ QStringLiteral("parentFolder"), { FileInfo{ QStringLiteral("subFolderA"), { { QStringLiteral("fileA.txt"), 400 } } }, FileInfo{ QStringLiteral("subFolderB"), { { QStringLiteral("fileB.txt"), 400 } } } } } } } }; + FakeFolder fakeFolder{ + FileInfo{QString(), { + FileInfo{QStringLiteral("parentFolder"), { + FileInfo{QStringLiteral("subFolderA"), { + {QStringLiteral("fileA.txt"), 400} + } + }, + FileInfo{QStringLiteral("subFolderB"), { + {QStringLiteral("fileB.txt"), 400} + } + } + } + } + } + } + }; QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); auto expectedServerState = fakeFolder.currentRemoteState();