Parcourir la source

Ensure the callback is triggered

Hannah von Reth il y a 5 ans
Parent
commit
440b31986a
2 fichiers modifiés avec 19 ajouts et 2 suppressions
  1. 11 2
      src/libsync/syncengine.cpp
  2. 8 0
      test/syncenginetestutils.h

+ 11 - 2
src/libsync/syncengine.cpp

@@ -732,7 +732,15 @@ void SyncEngine::slotDiscoveryFinished()
                 side += it->_direction == SyncFileItem::Down ? 1 : -1;
             }
         }
-        emit aboutToRemoveAllFiles(side >= 0 ? SyncFileItem::Down : SyncFileItem::Up, [this, finish](bool cancel){
+
+        QPointer<QObject> guard = new QObject();
+        auto callback = [this, finish, guard](bool cancel) -> void {
+            // use a guard to ensure its only called once...
+            if (!guard)
+            {
+                return;
+            }
+            guard->deleteLater();
             if (cancel) {
                 qCInfo(lcEngine) << "User aborted sync";
                 finalize(false);
@@ -740,7 +748,8 @@ void SyncEngine::slotDiscoveryFinished()
             } else {
                 finish();
             }
-        });
+        };
+        emit aboutToRemoveAllFiles(side >= 0 ? SyncFileItem::Down : SyncFileItem::Up, callback);
         return;
     }
     finish();

+ 8 - 0
test/syncenginetestutils.h

@@ -23,6 +23,7 @@
 #include <memory>
 
 #include <cookiejar.h>
+#include <QTimer>
 
 /*
  * TODO: In theory we should use QVERIFY instead of Q_ASSERT for testing, but this
@@ -991,6 +992,13 @@ public:
         // Ignore temporary files from the download. (This is in the default exclude list, but we don't load it)
         _syncEngine->excludedFiles().addManualExclude("]*.~*");
 
+        // handle aboutToRemoveAllFiles with a timeout in case our test does not handle it
+        QObject::connect(_syncEngine.get(), &OCC::SyncEngine::aboutToRemoveAllFiles, _syncEngine.get(), [this](OCC::SyncFileItem::Direction, std::function<void(bool)> callback){
+            QTimer::singleShot(1 * 1000, _syncEngine.get(), [callback]{
+                callback(false);
+            });
+        });
+
         // Ensure we have a valid VfsOff instance "running"
         switchToVfs(_syncEngine->syncOptions()._vfs);