diff --git a/src/base/bittorrent/filesearcher.cpp b/src/base/bittorrent/filesearcher.cpp index 9b1a1f9cc..e7241b889 100644 --- a/src/base/bittorrent/filesearcher.cpp +++ b/src/base/bittorrent/filesearcher.cpp @@ -63,10 +63,8 @@ namespace } void FileSearcher::search(const PathList &originalFileNames, const Path &savePath - , const Path &downloadPath, const bool forceAppendExt, QPromise promise) + , const Path &downloadPath, const bool forceAppendExt, QPromise &promise) { - promise.start(); - Path usedPath = savePath; PathList adjustedFileNames = originalFileNames; const bool found = findInDir(usedPath, adjustedFileNames, (forceAppendExt && downloadPath.isEmpty())); @@ -77,5 +75,4 @@ void FileSearcher::search(const PathList &originalFileNames, const Path &savePat } promise.addResult(FileSearchResult {.savePath = usedPath, .fileNames = adjustedFileNames}); - promise.finish(); } diff --git a/src/base/bittorrent/filesearcher.h b/src/base/bittorrent/filesearcher.h index cfd7ada73..f225b95dc 100644 --- a/src/base/bittorrent/filesearcher.h +++ b/src/base/bittorrent/filesearcher.h @@ -49,5 +49,5 @@ public: using QObject::QObject; void search(const PathList &originalFileNames, const Path &savePath - , const Path &downloadPath, bool forceAppendExt, QPromise promise); + , const Path &downloadPath, bool forceAppendExt, QPromise &promise); }; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index d9827b150..f3d68cf5f 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -3008,9 +3008,11 @@ QFuture SessionImpl::findIncompleteFiles(const Path &savePath, { QPromise promise; QFuture future = promise.future(); + promise.start(); QMetaObject::invokeMethod(m_fileSearcher, [=, this, promise = std::move(promise)]() mutable { - m_fileSearcher->search(filePaths, savePath, downloadPath, isAppendExtensionEnabled(), std::move(promise)); + m_fileSearcher->search(filePaths, savePath, downloadPath, isAppendExtensionEnabled(), promise); + promise.finish(); }); return future; diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index a670db151..f4ae0e0fa 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -3055,9 +3055,9 @@ QFuture> TorrentImpl::invokeAsync(Func &&func) const { QPromise> promise; const auto future = promise.future(); + promise.start(); m_session->invokeAsync([func = std::forward(func), promise = std::move(promise)]() mutable { - promise.start(); promise.addResult(func()); promise.finish(); });