From ba99c38d19630ebe2b3386fe5fb35fe25b20eccf Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 16 Oct 2019 12:12:02 +0200 Subject: [PATCH] Don't show the "All files deleted" popup when unselecting everything with selective sync Issue #7337 --- src/libsync/discovery.cpp | 1 + src/libsync/syncengine.cpp | 2 +- src/libsync/syncfileitem.h | 2 ++ test/testallfilesdeleted.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/libsync/discovery.cpp b/src/libsync/discovery.cpp index 163f69ef27..702ff41b04 100644 --- a/src/libsync/discovery.cpp +++ b/src/libsync/discovery.cpp @@ -1157,6 +1157,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; diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index d26ff6d710..1302382660 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -375,7 +375,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 diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index 667341be3c..f6740c5c8f 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -105,6 +105,7 @@ public: , _errorMayBeBlacklisted(false) , _status(NoStatus) , _isRestoration(false) + , _isSelectiveSync(false) , _httpErrorCode(0) , _affectedItems(1) , _instruction(CSYNC_INSTRUCTION_NONE) @@ -241,6 +242,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; RemotePermissions _remotePerm; QString _errorString; // Contains a string only in case of error diff --git a/test/testallfilesdeleted.cpp b/test/testallfilesdeleted.cpp index e49506a6bc..e5505fb0f2 100644 --- a/test/testallfilesdeleted.cpp +++ b/test/testallfilesdeleted.cpp @@ -295,6 +295,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)