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

Commit 89979b3

Browse files
authored
fix: nightly updater (#1202)
* fix: nightly updater * fix: correct temp * fix: add e2e test
1 parent 82f7823 commit 89979b3

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

engine/commands/cortex_upd_cmd.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ bool CortexUpdCmd::GetStableAndBeta(const std::string& v) {
138138

139139
// Replace binary file
140140
auto executable_path = file_manager_utils::GetExecutableFolderContainerPath();
141-
auto src = executable_path / "cortex" / kCortexBinary / GetCortexBinary();
141+
auto src = std::filesystem::temp_directory_path() / "cortex" / kCortexBinary /
142+
GetCortexBinary();
142143
auto dst = executable_path / GetCortexBinary();
143144
return ReplaceBinaryInflight(src, dst);
144145
}
@@ -159,7 +160,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
159160
std::ostringstream release_path;
160161
release_path << "cortex/" << version << "/" << system_info.os << "-"
161162
<< system_info.arch << "/" << kNightlyFileName;
162-
CTL_INF("Engine release path: " << kNightlyHost << release_path.str());
163+
CTL_INF("Engine release path: " << kNightlyHost << "/" << release_path.str());
163164

164165
auto download_task = DownloadTask{.id = "cortex",
165166
.type = DownloadType::Cortex,
@@ -190,7 +191,8 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
190191

191192
// Replace binay file
192193
auto executable_path = file_manager_utils::GetExecutableFolderContainerPath();
193-
auto src = executable_path / "cortex" / GetCortexBinary();
194+
auto src = std::filesystem::temp_directory_path() / "cortex" / kCortexBinary /
195+
GetCortexBinary();
194196
auto dst = executable_path / GetCortexBinary();
195197
return ReplaceBinaryInflight(src, dst);
196198
}

engine/commands/cortex_upd_cmd.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ inline void CheckNewUpdate() {
6262
if (current_version != latest_version) {
6363
CLI_LOG("\nA new release of cortex is available: "
6464
<< current_version << " -> " << latest_version);
65-
CLI_LOG("To upgrade, run: cortex update");
66-
// CLI_LOG(json_res["html_url"].get<std::string>());
65+
CLI_LOG("To upgrade, run: " << GetCortexBinary() << " update");
66+
if (CORTEX_VARIANT == file_manager_utils::kProdVariant) {
67+
CLI_LOG(json_res["html_url"].get<std::string>());
68+
}
6769
}
6870
} catch (const nlohmann::json::parse_error& e) {
6971
CTL_INF("JSON parse error: " << e.what());
@@ -83,7 +85,7 @@ inline bool ReplaceBinaryInflight(const std::filesystem::path& src,
8385
// Already has the newest
8486
return true;
8587
}
86-
std::filesystem::path temp = std::filesystem::temp_directory_path() / "cortex_temp";
88+
std::filesystem::path temp = dst.parent_path() / "cortex_temp";
8789

8890
try {
8991
if (std::filesystem::exists(temp)) {
@@ -97,8 +99,6 @@ inline bool ReplaceBinaryInflight(const std::filesystem::path& src,
9799
std::filesystem::perms::group_all |
98100
std::filesystem::perms::others_read |
99101
std::filesystem::perms::others_exec);
100-
auto download_folder = src.parent_path();
101-
std::filesystem::remove_all(download_folder);
102102
} catch (const std::exception& e) {
103103
CTL_ERR("Something wrong happened: " << e.what());
104104
if (std::filesystem::exists(temp)) {

engine/e2e-test/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from test_cli_engine_install import TestCliEngineInstall
55
from test_cli_engine_list import TestCliEngineList
66
from test_cli_engine_uninstall import TestCliEngineUninstall
7+
from test_cortex_update import TestCortexUpdate
78
from test_cli_server_start import TestCliServerStart
89
from test_create_log_folder import TestCreateLogFolder
910

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import platform
2+
3+
import pytest
4+
from test_runner import run
5+
6+
7+
class TestCortexUpdate:
8+
# We don't have stable release yet, so mark this test as skip for now
9+
# Only able to test with beta and nightly
10+
@pytest.mark.skip(reason="Stable release is not available yet")
11+
def test_cortex_update(self):
12+
exit_code, output, error = run("Update cortex", ["update"])
13+
assert exit_code == 0, f"Something wrong happened"
14+
assert "Update cortex sucessfully" in output

engine/main.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "utils/file_logger.h"
1010
#include "utils/file_manager_utils.h"
1111
#include "utils/logging_utils.h"
12+
#include "commands/cortex_upd_cmd.h"
1213

1314
#if defined(__APPLE__) && defined(__MACH__)
1415
#include <libgen.h> // for dirname()
@@ -91,8 +92,9 @@ void ForkProcess() {
9192
ZeroMemory(&si, sizeof(si));
9293
si.cb = sizeof(si);
9394
ZeroMemory(&pi, sizeof(pi));
95+
auto exe = commands::GetCortexBinary();
9496
std::string cmds =
95-
cortex_utils::GetCurrentPath() + "/cortex-cpp.exe --start-server";
97+
cortex_utils::GetCurrentPath() + "/" + exe + " --start-server";
9698
// Create child process
9799
if (!CreateProcess(
98100
NULL, // No module name (use command line)
@@ -133,6 +135,17 @@ void ForkProcess() {
133135
int main(int argc, char* argv[]) {
134136
{ file_manager_utils::CreateConfigFileIfNotExist(); }
135137

138+
// Delete temporary file if it exists
139+
auto temp =
140+
file_manager_utils::GetExecutableFolderContainerPath() / "cortex_temp";
141+
if (std::filesystem::exists(temp)) {
142+
try {
143+
std::filesystem::remove(temp);
144+
} catch (const std::exception& e) {
145+
std::cerr << e.what() << '\n';
146+
}
147+
}
148+
136149
// Check if this process is for python execution
137150
if (argc > 1) {
138151
if (strcmp(argv[1], "--run_python_file") == 0) {

engine/utils/file_manager_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ inline std::filesystem::path GetContainerFolderPath(
230230
} else if (type == "CudaToolkit") {
231231
container_folder_path = current_path;
232232
} else if (type == "Cortex") {
233-
container_folder_path = current_path / "cortex";
233+
container_folder_path = std::filesystem::temp_directory_path() / "cortex";
234234
} else {
235235
container_folder_path = current_path / "misc";
236236
}

0 commit comments

Comments
 (0)