Don't crash when the same request is filled twice
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 25 Jan 2021 17:02:42 +0000 (18:02 +0100)
committerKevin Ottens (Rebase PR Action) <er-vin@users.noreply.github.com>
Tue, 26 Jan 2021 10:58:14 +0000 (10:58 +0000)
The OS might request the same file again if we take too much time to
fulfill a request. So in case it's queueing the same one again instead
of bailing out just fail the second one and let the first one finish
properly.

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

index 7a5da1e0ed4f5639e17b5b8bebdb820ff35a7817..be0eb5f239ff9fc3e189ad4a4ed4c362b1ce7389 100644 (file)
@@ -307,9 +307,15 @@ void VfsCfApi::fileStatusChanged(const QString &systemFileName, SyncFileStatus f
 
 void VfsCfApi::scheduleHydrationJob(const QString &requestId, const QString &folderPath)
 {
-    Q_ASSERT(std::none_of(std::cbegin(d->hydrationJobs), std::cend(d->hydrationJobs), [=](HydrationJob *job) {
+    const auto jobAlreadyScheduled = std::any_of(std::cbegin(d->hydrationJobs), std::cend(d->hydrationJobs), [=](HydrationJob *job) {
         return job->requestId() == requestId || job->folderPath() == folderPath;
-    }));
+    });
+
+    if (jobAlreadyScheduled) {
+        qCWarning(lcCfApi) << "The OS submitted again a hydration request which is already on-going" << requestId << folderPath;
+        emit hydrationRequestFailed(requestId);
+        return;
+    }
 
     if (d->hydrationJobs.isEmpty()) {
         emit beginHydrating();