Skip to content

Commit

Permalink
when moving a file, checks that it exists at origin or destination
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mgallien committed Feb 19, 2024
1 parent 334e032 commit 22c1725
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/libsync/propagatorjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion test/testsyncmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 22c1725

Please sign in to comment.