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

Commit 9d39a50

Browse files
authored
fix: pull issue (#1381)
1 parent c12a78f commit 9d39a50

File tree

6 files changed

+34
-32
lines changed

6 files changed

+34
-32
lines changed

engine/commands/engine_install_cmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void EngineInstallCmd::Exec(const std::string& engine,
99
auto result = engine_service_.InstallEngine(engine, version, src);
1010
if (result.has_error()) {
1111
CLI_LOG(result.error());
12-
} else {
12+
} else if(result && result.value()){
1313
CLI_LOG("Engine " << engine << " installed successfully!");
1414
}
1515
}

engine/services/download_service.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ cpp::result<void, std::string> DownloadService::VerifyDownloadTask(
5353
return {};
5454
}
5555

56-
cpp::result<void, std::string> DownloadService::AddDownloadTask(
56+
cpp::result<bool, std::string> DownloadService::AddDownloadTask(
5757
DownloadTask& task,
5858
std::optional<OnDownloadTaskSuccessfully> callback) noexcept {
5959
auto validating_result = VerifyDownloadTask(task);
@@ -65,12 +65,15 @@ cpp::result<void, std::string> DownloadService::AddDownloadTask(
6565
// if any item from the task failed to download, the whole task will be
6666
// considered failed
6767
std::optional<std::string> dl_err_msg = std::nullopt;
68+
bool has_task_done = false;
6869
for (const auto& item : task.items) {
6970
CLI_LOG("Start downloading: " + item.localPath.filename().string());
7071
auto result = Download(task.id, item, true);
7172
if (result.has_error()) {
7273
dl_err_msg = result.error();
7374
break;
75+
} else if(result) {
76+
has_task_done |= result.value();
7477
}
7578
}
7679
if (dl_err_msg.has_value()) {
@@ -81,7 +84,7 @@ cpp::result<void, std::string> DownloadService::AddDownloadTask(
8184
if (callback.has_value()) {
8285
callback.value()(task);
8386
}
84-
return {};
87+
return has_task_done;
8588
}
8689

8790
cpp::result<uint64_t, std::string> DownloadService::GetFileSize(
@@ -109,7 +112,7 @@ cpp::result<uint64_t, std::string> DownloadService::GetFileSize(
109112
return content_length;
110113
}
111114

112-
cpp::result<void, std::string> DownloadService::AddAsyncDownloadTask(
115+
cpp::result<bool, std::string> DownloadService::AddAsyncDownloadTask(
113116
DownloadTask& task,
114117
std::optional<OnDownloadTaskSuccessfully> callback) noexcept {
115118
auto verifying_result = VerifyDownloadTask(task);
@@ -142,10 +145,10 @@ cpp::result<void, std::string> DownloadService::AddAsyncDownloadTask(
142145
std::thread t(execute_download_async);
143146
t.detach();
144147

145-
return {};
148+
return true;
146149
}
147150

148-
cpp::result<void, std::string> DownloadService::Download(
151+
cpp::result<bool, std::string> DownloadService::Download(
149152
const std::string& download_id, const DownloadItem& download_item,
150153
bool allow_resume) noexcept {
151154
CTL_INF("Absolute file output: " << download_item.localPath.string());
@@ -182,8 +185,7 @@ cpp::result<void, std::string> DownloadService::Download(
182185
mode = "ab";
183186
CLI_LOG("Resuming download..");
184187
} else {
185-
CLI_LOG("Start over..");
186-
return cpp::fail("Cancelled Resume download!");
188+
CLI_LOG("Start over..");
187189
}
188190
} else {
189191
CLI_LOG(download_item.localPath.filename().string()
@@ -195,7 +197,7 @@ cpp::result<void, std::string> DownloadService::Download(
195197
if (answer == "Y" || answer == "y" || answer.empty()) {
196198
CLI_LOG("Re-downloading..");
197199
} else {
198-
return cpp::fail("Cancelled Re-download!");
200+
return false;
199201
}
200202
}
201203
}
@@ -232,7 +234,7 @@ cpp::result<void, std::string> DownloadService::Download(
232234

233235
fclose(file);
234236
curl_easy_cleanup(curl);
235-
return {};
237+
return true;
236238
}
237239

238240
curl_off_t DownloadService::GetLocalFileSize(

engine/services/download_service.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ class DownloadService {
5757
using OnDownloadTaskSuccessfully =
5858
std::function<void(const DownloadTask& task)>;
5959

60-
cpp::result<void, std::string> AddDownloadTask(
60+
cpp::result<bool, std::string> AddDownloadTask(
6161
DownloadTask& task, std::optional<OnDownloadTaskSuccessfully> callback =
6262
std::nullopt) noexcept;
6363

64-
cpp::result<void, std::string> AddAsyncDownloadTask(
64+
cpp::result<bool, std::string> AddAsyncDownloadTask(
6565
DownloadTask& task, std::optional<OnDownloadTaskSuccessfully> callback =
6666
std::nullopt) noexcept;
6767

@@ -77,7 +77,7 @@ class DownloadService {
7777
cpp::result<void, std::string> VerifyDownloadTask(
7878
DownloadTask& task) const noexcept;
7979

80-
cpp::result<void, std::string> Download(
80+
cpp::result<bool, std::string> Download(
8181
const std::string& download_id, const DownloadItem& download_item,
8282
bool allow_resume) noexcept;
8383

engine/services/engine_service.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ std::vector<EngineInfo> EngineService::GetEngineInfoList() const {
116116
return engines;
117117
}
118118

119-
cpp::result<void, std::string> EngineService::InstallEngine(
119+
cpp::result<bool, std::string> EngineService::InstallEngine(
120120
const std::string& engine, const std::string& version,
121121
const std::string& src) {
122122

@@ -131,7 +131,7 @@ cpp::result<void, std::string> EngineService::InstallEngine(
131131
}
132132
}
133133

134-
cpp::result<void, std::string> EngineService::UnzipEngine(
134+
cpp::result<bool, std::string> EngineService::UnzipEngine(
135135
const std::string& engine, const std::string& version,
136136
const std::string& path) {
137137
bool found_cuda = false;
@@ -193,10 +193,10 @@ cpp::result<void, std::string> EngineService::UnzipEngine(
193193
return DownloadCuda(engine);
194194
}
195195

196-
return {};
196+
return true;
197197
}
198198

199-
cpp::result<void, std::string> EngineService::UninstallEngine(
199+
cpp::result<bool, std::string> EngineService::UninstallEngine(
200200
const std::string& engine) {
201201
auto ecp = file_manager_utils::GetEnginesContainerPath();
202202
auto engine_path = ecp / engine;
@@ -208,14 +208,14 @@ cpp::result<void, std::string> EngineService::UninstallEngine(
208208
try {
209209
std::filesystem::remove_all(engine_path);
210210
CTL_INF("Engine " << engine << " uninstalled successfully!");
211-
return {};
211+
return true;
212212
} catch (const std::exception& e) {
213213
CTL_ERR("Failed to uninstall engine " << engine << ": " << e.what());
214214
return cpp::fail("Failed to uninstall engine " + engine + ": " + e.what());
215215
}
216216
}
217217

218-
cpp::result<void, std::string> EngineService::DownloadEngine(
218+
cpp::result<bool, std::string> EngineService::DownloadEngine(
219219
const std::string& engine, const std::string& version) {
220220
auto get_params = [&engine, &version]() -> std::vector<std::string> {
221221
if (version == "latest") {
@@ -322,22 +322,22 @@ cpp::result<void, std::string> EngineService::DownloadEngine(
322322
});
323323
}
324324
}
325-
return {};
325+
return true;
326326
} else {
327327
return cpp::fail("Failed to fetch engine release: " + engine);
328328
}
329329
}
330330

331-
cpp::result<void, std::string> EngineService::DownloadCuda(
331+
cpp::result<bool, std::string> EngineService::DownloadCuda(
332332
const std::string& engine) {
333333
if (hw_inf_.sys_inf->os == "mac" || engine == "cortex.onnx") {
334334
// mac and onnx engine does not require cuda toolkit
335-
return {};
335+
return true;
336336
}
337337

338338
if (hw_inf_.cuda_driver_version.empty()) {
339339
CTL_WRN("No cuda driver, continue with CPU");
340-
return {};
340+
return true;
341341
}
342342
// download cuda toolkit
343343
const std::string jan_host = "catalog.jan.ai";

engine/services/engine_service.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ class EngineService {
3838

3939
std::vector<EngineInfo> GetEngineInfoList() const;
4040

41-
cpp::result<void, std::string> InstallEngine(
41+
cpp::result<bool, std::string> InstallEngine(
4242
const std::string& engine, const std::string& version = "latest",
4343
const std::string& src = "");
4444

45-
cpp::result<void, std::string> UninstallEngine(const std::string& engine);
45+
cpp::result<bool, std::string> UninstallEngine(const std::string& engine);
4646

4747
private:
48-
cpp::result<void, std::string> UnzipEngine(const std::string& engine,
48+
cpp::result<bool, std::string> UnzipEngine(const std::string& engine,
4949
const std::string& version,
5050
const std::string& path);
5151

52-
cpp::result<void, std::string> DownloadEngine(
52+
cpp::result<bool, std::string> DownloadEngine(
5353
const std::string& engine, const std::string& version = "latest");
5454

55-
cpp::result<void, std::string> DownloadCuda(const std::string& engine);
55+
cpp::result<bool, std::string> DownloadCuda(const std::string& engine);
5656

5757
std::string GetMatchedVariant(const std::string& engine,
5858
const std::vector<std::string>& variants);

engine/services/model_service.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ cpp::result<std::string, std::string> ModelService::HandleUrl(
242242
if (result.has_error()) {
243243
// CTL_ERR(result.error());
244244
return cpp::fail(result.error());
245-
} else {
245+
} else if (result && result.value()) {
246246
CLI_LOG("Model " << model_id << " downloaded successfully!")
247247
}
248248
return unique_model_id;
@@ -295,7 +295,7 @@ cpp::result<std::string, std::string> ModelService::DownloadModelFromCortexso(
295295

296296
if (result.has_error()) {
297297
return cpp::fail(result.error());
298-
} else {
298+
} else if (result && result.value()) {
299299
CLI_LOG("Model " << model_id << " downloaded successfully!")
300300
}
301301

@@ -415,7 +415,7 @@ cpp::result<bool, std::string> ModelService::StartModel(
415415
auto res = cli.Post("/inferences/server/loadmodel", httplib::Headers(),
416416
data_str.data(), data_str.size(), "application/json");
417417
if (res) {
418-
if (res->status == httplib::StatusCode::OK_200) {
418+
if (res->status == httplib::StatusCode::OK_200) {
419419
return true;
420420
} else {
421421
CTL_ERR("Model failed to load with status code: " << res->status);
@@ -459,7 +459,7 @@ cpp::result<bool, std::string> ModelService::StopModel(
459459
auto res = cli.Post("/inferences/server/unloadmodel", httplib::Headers(),
460460
data_str.data(), data_str.size(), "application/json");
461461
if (res) {
462-
if (res->status == httplib::StatusCode::OK_200) {
462+
if (res->status == httplib::StatusCode::OK_200) {
463463
return true;
464464
} else {
465465
CTL_ERR("Model failed to unload with status code: " << res->status);

0 commit comments

Comments
 (0)