From: Olivier Goffart Date: Tue, 14 Aug 2018 07:19:31 +0000 (+0200) Subject: SyncEngine: Fix the "direction" of the "all file delted" message when the server... X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~528 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=732069aaa77b3225239aa5fc74faa37a5b50aac2;p=nextcloud-desktop.git SyncEngine: Fix the "direction" of the "all file delted" message when the server is reset Using the direction of the "first" item is not enough as it might be a directory which is a UPDATE_META_DATA, or there can have been a few changes locally as well. As reported on https://github.com/owncloud/client/issues/6317#issuecomment-412163113 --- diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index ffbc65350..84337cee6 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -690,7 +690,13 @@ void SyncEngine::slotDiscoveryJobFinished() if (!_hasNoneFiles && _hasRemoveFile && cfgFile.promptDeleteFiles()) { qCInfo(lcEngine) << "All the files are going to be changed, asking the user"; bool cancel = false; - emit aboutToRemoveAllFiles(_syncItems.first()->_direction, &cancel); + int side = 0; // > 0 means more deleted on the server. < 0 means more deleted on the client + foreach (const auto &it, _syncItems) { + if (it->_instruction == CSYNC_INSTRUCTION_REMOVE) { + side += it->_direction == SyncFileItem::Down ? 1 : -1; + } + } + emit aboutToRemoveAllFiles(side >= 0 ? SyncFileItem::Down : SyncFileItem::Up, &cancel); if (cancel) { qCInfo(lcEngine) << "User aborted sync"; finalize(false); diff --git a/test/testallfilesdeleted.cpp b/test/testallfilesdeleted.cpp index 026aa7a60..f85debef3 100644 --- a/test/testallfilesdeleted.cpp +++ b/test/testallfilesdeleted.cpp @@ -155,6 +155,38 @@ private slots: QCOMPARE(fakeFolder.currentRemoteState(), expectedState); } + void testResetServer() + { + FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()}; + + int aboutToRemoveAllFilesCalled = 0; + QObject::connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToRemoveAllFiles, + [&](SyncFileItem::Direction dir, bool *cancel) { + QCOMPARE(aboutToRemoveAllFilesCalled, 0); + aboutToRemoveAllFilesCalled++; + QCOMPARE(dir, SyncFileItem::Down); + *cancel = false; + }); + + // Some small changes + fakeFolder.localModifier().mkdir("Q"); + fakeFolder.localModifier().insert("Q/q1"); + fakeFolder.localModifier().appendByte("B/b1"); + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(aboutToRemoveAllFilesCalled, 0); + + // Do some change localy + fakeFolder.localModifier().appendByte("A/a1"); + + // reset the server. + fakeFolder.remoteModifier() = FileInfo::A12_B12_C12_S12(); + + // Now, aboutToRemoveAllFiles with down as a direction + QVERIFY(fakeFolder.syncOnce()); + QCOMPARE(aboutToRemoveAllFilesCalled, 1); + + } + void testDataFingetPrint_data() { QTest::addColumn("hasInitialFingerPrint");