From: Olivier Goffart Date: Tue, 4 Jun 2019 10:08:15 +0000 (+0200) Subject: SyncEngine: Fix renaming a single file cause the "delete all file" popup X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~233 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9f08636a4a8a16f3e043baf2e8eff24ed65258d2;p=nextcloud-desktop.git 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 --- 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)