From 9f08636a4a8a16f3e043baf2e8eff24ed65258d2 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 4 Jun 2019 12:08:15 +0200 Subject: [PATCH] SyncEngine: Fix renaming a single file cause the "delete all file" popup Possibly a regression, since the new discovery discovers rist the renamed files as removed Issue #7204 --- src/libsync/syncengine.cpp | 2 ++ test/testallfilesdeleted.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index eecf40fc8..d5bcd0cc6 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -382,6 +382,8 @@ void OCC::SyncEngine::slotItemDiscovered(const OCC::SyncFileItemPtr &item) return; } else if (item->_instruction == CSYNC_INSTRUCTION_REMOVE) { _hasRemoveFile = true; + } else if (item->_instruction == CSYNC_INSTRUCTION_RENAME) { + _hasNoneFiles = true; // If a file (or every file) has been renamed, it means not al files where deleted } else if (item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE || item->_instruction == CSYNC_INSTRUCTION_SYNC) { if (item->_direction == SyncFileItem::Up) { diff --git a/test/testallfilesdeleted.cpp b/test/testallfilesdeleted.cpp index 894503f10..1c4853d2c 100644 --- a/test/testallfilesdeleted.cpp +++ b/test/testallfilesdeleted.cpp @@ -274,6 +274,30 @@ private slots: QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); } + + void testSingleFileRenamed() { + FakeFolder fakeFolder{FileInfo{}}; + + int aboutToRemoveAllFilesCalled = 0; + QObject::connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToRemoveAllFiles, + [&](SyncFileItem::Direction , bool *) { + aboutToRemoveAllFilesCalled++; + QFAIL("should not be called"); + }); + + // add a single file + fakeFolder.localModifier().insert("hello.txt"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(aboutToRemoveAllFilesCalled, 0); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + + // rename it + fakeFolder.localModifier().rename("hello.txt", "goodbye.txt"); + + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(aboutToRemoveAllFilesCalled, 0); + QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState()); + } }; QTEST_GUILESS_MAIN(TestAllFilesDeleted) -- 2.30.2