Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 354b953

Browse files
committed
fix: corrupt model download
1 parent 789d1b3 commit 354b953

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

engine/services/download_service.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <mutex>
77
#include <optional>
88
#include <ostream>
9+
#include <utility>
910
#include "download_service.h"
1011
#include "utils/format_utils.h"
1112
#include "utils/result.hpp"
@@ -238,7 +239,7 @@ void DownloadService::WorkerThread() {
238239

239240
void DownloadService::ProcessTask(DownloadTask& task) {
240241
CTL_INF("Processing task: " + task.id);
241-
std::vector<CURL*> task_handles;
242+
std::vector<std::pair<CURL*, FILE*>> task_handles;
242243

243244
downloading_data_ = std::make_shared<DownloadingData>(DownloadingData{
244245
.item_id = "",
@@ -247,7 +248,7 @@ void DownloadService::ProcessTask(DownloadTask& task) {
247248
});
248249

249250
for (auto& item : task.items) {
250-
auto handle = curl_easy_init();
251+
CURL* handle = curl_easy_init();
251252
if (handle == nullptr) {
252253
// skip the task
253254
CTL_ERR("Failed to init curl!");
@@ -270,7 +271,7 @@ void DownloadService::ProcessTask(DownloadTask& task) {
270271
curl_easy_setopt(handle, CURLOPT_XFERINFODATA, downloading_data_.get());
271272

272273
curl_multi_add_handle(multi_handle_, handle);
273-
task_handles.push_back(handle);
274+
task_handles.push_back(std::make_pair(handle, file));
274275
CTL_INF("Adding item to multi curl: " + item.ToString());
275276
}
276277

@@ -300,9 +301,10 @@ void DownloadService::ProcessTask(DownloadTask& task) {
300301
}
301302

302303
ProcessCompletedTransfers();
303-
for (auto handle : task_handles) {
304-
curl_multi_remove_handle(multi_handle_, handle);
305-
curl_easy_cleanup(handle);
304+
for (auto pair : task_handles) {
305+
curl_multi_remove_handle(multi_handle_, pair.first);
306+
curl_easy_cleanup(pair.first);
307+
fclose(pair.second);
306308
downloading_data_.reset();
307309
}
308310

0 commit comments

Comments
 (0)