Don't show the "All files deleted" popup when unselecting everything with selective...
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 16 Oct 2019 10:12:02 +0000 (12:12 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:04 +0000 (10:59 +0100)
Issue #7337

src/libsync/discovery.cpp
src/libsync/syncengine.cpp
src/libsync/syncfileitem.h
test/testallfilesdeleted.cpp

index 9ecb2a542a7171e2952228b7a7bb7e751e68bc33..7b403015f95e42396d9ef12e7935de2fa42f44db 100644 (file)
@@ -1167,6 +1167,7 @@ void ProcessDirectoryJob::processBlacklisted(const PathTuple &path, const OCC::L
     item->_file = path._target;
     item->_originalFile = path._original;
     item->_inode = localEntry.inode;
+    item->_isSelectiveSync = true;
     if (dbEntry.isValid() && ((dbEntry._modtime == localEntry.modtime && dbEntry._fileSize == localEntry.size) || (localEntry.isDirectory && dbEntry.isDirectory()))) {
         item->_instruction = CSYNC_INSTRUCTION_REMOVE;
         item->_direction = SyncFileItem::Down;
index a185dd2b0f2045e648f68dfc90158dcde833f31f..48bc8ac5ae5f0a84d7ea558a610676170cbb08f3 100644 (file)
@@ -381,7 +381,7 @@ void OCC::SyncEngine::slotItemDiscovered(const OCC::SyncFileItemPtr &item)
             item->_status = SyncFileItem::Conflict;
         }
         return;
-    } else if (item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
+    } else if (item->_instruction == CSYNC_INSTRUCTION_REMOVE && !item->_isSelectiveSync) {
         _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
index 36a6d925caa6b8b644e42a2492c121d528e2ca76..306b526dd0ca0bfca0ffb55373e206f17e6bb94e 100644 (file)
@@ -106,6 +106,7 @@ public:
         , _errorMayBeBlacklisted(false)
         , _status(NoStatus)
         , _isRestoration(false)
+        , _isSelectiveSync(false)
     {
     }
 
@@ -239,6 +240,7 @@ public:
     // Variables useful to report to the user
     Status _status BITFIELD(4);
     bool _isRestoration BITFIELD(1); // The original operation was forbidden, and this is a restoration
+    bool _isSelectiveSync BITFIELD(1); // The file is removed or ignored because it is in the selective sync list
     quint16 _httpErrorCode = 0;
     RemotePermissions _remotePerm;
     QString _errorString; // Contains a string only in case of error
index 1c4853d2cb7c9e3a0d1c754eb547ceae22872ea2..61a3f77a0a4fe0e03ca058cbe120c048850051f6 100644 (file)
@@ -298,6 +298,32 @@ private slots:
         QCOMPARE(aboutToRemoveAllFilesCalled, 0);
         QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
     }
+
+    void testSelectiveSyncNoPopup() {
+        // Unselecting all folder should not cause the popup to be shown
+        FakeFolder fakeFolder{FileInfo::A12_B12_C12_S12()};
+
+        int aboutToRemoveAllFilesCalled = 0;
+        QObject::connect(&fakeFolder.syncEngine(), &SyncEngine::aboutToRemoveAllFiles,
+            [&](SyncFileItem::Direction , bool *) {
+                aboutToRemoveAllFilesCalled++;
+                QFAIL("should not be called");
+            });
+
+        QVERIFY(fakeFolder.syncOnce());
+        QCOMPARE(aboutToRemoveAllFilesCalled, 0);
+        QCOMPARE(fakeFolder.currentLocalState(), fakeFolder.currentRemoteState());
+
+        fakeFolder.syncEngine().journal()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList,
+            QStringList() << "A/" << "B/" << "C/" << "S/");
+
+        QVERIFY(fakeFolder.syncOnce());
+        QCOMPARE(fakeFolder.currentLocalState(), FileInfo{}); // all files should be one localy
+        QCOMPARE(fakeFolder.currentRemoteState(), FileInfo::A12_B12_C12_S12()); // Server not changed
+        QCOMPARE(aboutToRemoveAllFilesCalled, 0); // But we did not show the popup
+    }
+
+
 };
 
 QTEST_GUILESS_MAIN(TestAllFilesDeleted)