Don't use mutable lambdas as they hide where we modify work on a copy
authorHannah von Reth <hannah.vonreth@owncloud.com>
Wed, 21 Aug 2019 09:52:11 +0000 (11:52 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:55 +0000 (10:58 +0100)
src/libsync/discovery.cpp

index 8472b819d546ab06cb71276a01aa0bf9fde43f82..d08adbb79f4612b6c8fd3809bf7ec42fe74a98fd 100644 (file)
@@ -438,14 +438,15 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
     item->_modtime = serverEntry.modtime;
     item->_size = serverEntry.size;
 
-    auto postProcessServerNew = [item, this, path, serverEntry, localEntry, dbEntry] () mutable {
+    auto postProcessServerNew = [=] () {
+        auto tmp_path = path;
         if (item->isDirectory()) {
             _pendingAsyncJobs++;
-            _discoveryData->checkSelectiveSyncNewFolder(path._server, serverEntry.remotePerm,
+            _discoveryData->checkSelectiveSyncNewFolder(tmp_path._server, serverEntry.remotePerm,
                 [=](bool result) {
                     --_pendingAsyncJobs;
                     if (!result) {
-                        processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
+                        processFileAnalyzeLocalInfo(item, tmp_path, localEntry, serverEntry, dbEntry, _queryServer);
                     }
                     QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
                 });
@@ -459,9 +460,9 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
             && _pinState != PinState::AlwaysLocal) {
             item->_type = ItemTypeVirtualFile;
             if (isVfsWithSuffix())
-                addVirtualFileSuffix(path._original);
+                addVirtualFileSuffix(tmp_path._original);
         }
-        processFileAnalyzeLocalInfo(item, path, localEntry, serverEntry, dbEntry, _queryServer);
+        processFileAnalyzeLocalInfo(item, tmp_path, localEntry, serverEntry, dbEntry, _queryServer);
     };
 
     // Potential NEW/NEW conflict is handled in AnalyzeLocal
@@ -580,7 +581,8 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
             // we need to make a request to the server to know that the original file is deleted on the server
             _pendingAsyncJobs++;
             auto job = new RequestEtagJob(_discoveryData->_account, originalPath, this);
-            connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QString> &etag) mutable {
+            connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QString> &etag) {
+                auto tmp_path = path;
                 _pendingAsyncJobs--;
                 QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
                 if (etag || etag.error().code != 404 ||
@@ -596,8 +598,8 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
                 // In case the deleted item was discovered in parallel
                 _discoveryData->findAndCancelDeletedJob(originalPath);
 
-                postProcessRename(path);
-                processFileFinalize(item, path, item->isDirectory(), item->_instruction == CSYNC_INSTRUCTION_RENAME ? NormalQuery : ParentDontExist, _queryServer);
+                postProcessRename(tmp_path);
+                processFileFinalize(item, tmp_path, item->isDirectory(), item->_instruction == CSYNC_INSTRUCTION_RENAME ? NormalQuery : ParentDontExist, _queryServer);
             });
             job->start();
             done = true; // Ideally, if the origin still exist on the server, we should continue searching...  but that'd be difficult
@@ -951,7 +953,9 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
             if (base.isVirtualFile() && isVfsWithSuffix())
                 chopVirtualFileSuffix(serverOriginalPath);
             auto job = new RequestEtagJob(_discoveryData->_account, serverOriginalPath, this);
-            connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QString> &etag) mutable {
+            connect(job, &RequestEtagJob::finishedWithResult, this, [=](const HttpResult<QString> &etag) {
+                auto tmp_path = path;
+                auto tmp_recurseQueryServer = recurseQueryServer;
                 if (!etag || (*etag != base._etag && !item->isDirectory()) || _discoveryData->isRenamed(originalPath)) {
                     qCInfo(lcDisco) << "Can't rename because the etag has changed or the directory is gone" << originalPath;
                     // Can't be a rename, leave it as a new.
@@ -959,10 +963,10 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
                 } else {
                     // In case the deleted item was discovered in parallel
                     _discoveryData->findAndCancelDeletedJob(originalPath);
-                    processRename(path);
-                    recurseQueryServer = *etag == base._etag ? ParentNotChanged : NormalQuery;
+                    processRename(tmp_path);
+                    tmp_recurseQueryServer = *etag == base._etag ? ParentNotChanged : NormalQuery;
                 }
-                processFileFinalize(item, path, item->isDirectory(), NormalQuery, recurseQueryServer);
+                processFileFinalize(item, tmp_path, item->isDirectory(), NormalQuery, tmp_recurseQueryServer);
                 _pendingAsyncJobs--;
                 QTimer::singleShot(0, _discoveryData, &DiscoveryPhase::scheduleMoreJobs);
             });