SyncEngine: Fix the "direction" of the "all file delted" message when the server...
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 14 Aug 2018 07:19:31 +0000 (09:19 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:02 +0000 (10:58 +0100)
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

src/libsync/syncengine.cpp
test/testallfilesdeleted.cpp

index ffbc65350b7605ee75e6a985742668294c0a591b..84337cee6cadec616b9cebec9ee91b9eb24e8b9d 100644 (file)
@@ -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);
index 026aa7a60964cdea3693262bc373874952a8ee75..f85debef39645c6a66d43a1a58bd4f2eb229b1bc 100644 (file)
@@ -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<bool>("hasInitialFingerPrint");