Make sure we don't assert when calling fileStatus
authorKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 18 Aug 2020 08:23:52 +0000 (10:23 +0200)
committerCamila <hello@camila.codes>
Tue, 18 Aug 2020 11:52:28 +0000 (13:52 +0200)
It happens that sometimes we leak a directory path ending with a slash,
but that violates fileStatus' precondition so let's catch it early and
skip such path.

Of course the right fix would be a larger swipe in the sync engine and
around it to not use naked strings anymore but rely on the typesystem.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/syncfilestatustracker.cpp

index 1c69da1718e79e20ecb2d4aa1a6dfedbb26213cf..ecafde7000ea7aed4166dc483e11934615ba66cf 100644 (file)
@@ -290,8 +290,14 @@ void SyncFileStatusTracker::slotSyncFinished()
     // Clear the sync counts to reduce the impact of unsymetrical inc/dec calls (e.g. when directory job abort)
     QHash<QString, int> oldSyncCount;
     std::swap(_syncCount, oldSyncCount);
-    for (auto it = oldSyncCount.begin(); it != oldSyncCount.end(); ++it)
+    for (auto it = oldSyncCount.begin(); it != oldSyncCount.end(); ++it) {
+        // Don't announce folders, fileStatus expect only paths without '/', otherwise it asserts
+        if (it.key().endsWith('/')) {
+            continue;
+        }
+
         emit fileStatusChanged(getSystemDestination(it.key()), fileStatus(it.key()));
+    }
 }
 
 void SyncFileStatusTracker::slotSyncEngineRunningChanged()