diff --git a/engine/commands/cortex_upd_cmd.cc b/engine/commands/cortex_upd_cmd.cc index a4343e55c..ca25f63d3 100644 --- a/engine/commands/cortex_upd_cmd.cc +++ b/engine/commands/cortex_upd_cmd.cc @@ -138,7 +138,8 @@ bool CortexUpdCmd::GetStableAndBeta(const std::string& v) { // Replace binary file auto executable_path = file_manager_utils::GetExecutableFolderContainerPath(); - auto src = executable_path / "cortex" / kCortexBinary / GetCortexBinary(); + auto src = std::filesystem::temp_directory_path() / "cortex" / kCortexBinary / + GetCortexBinary(); auto dst = executable_path / GetCortexBinary(); return ReplaceBinaryInflight(src, dst); } @@ -159,7 +160,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) { std::ostringstream release_path; release_path << "cortex/" << version << "/" << system_info.os << "-" << system_info.arch << "/" << kNightlyFileName; - CTL_INF("Engine release path: " << kNightlyHost << release_path.str()); + CTL_INF("Engine release path: " << kNightlyHost << "/" << release_path.str()); auto download_task = DownloadTask{.id = "cortex", .type = DownloadType::Cortex, @@ -190,7 +191,8 @@ bool CortexUpdCmd::GetNightly(const std::string& v) { // Replace binay file auto executable_path = file_manager_utils::GetExecutableFolderContainerPath(); - auto src = executable_path / "cortex" / GetCortexBinary(); + auto src = std::filesystem::temp_directory_path() / "cortex" / kCortexBinary / + GetCortexBinary(); auto dst = executable_path / GetCortexBinary(); return ReplaceBinaryInflight(src, dst); } diff --git a/engine/commands/cortex_upd_cmd.h b/engine/commands/cortex_upd_cmd.h index 396c6cdaf..b8aac9e7b 100644 --- a/engine/commands/cortex_upd_cmd.h +++ b/engine/commands/cortex_upd_cmd.h @@ -62,8 +62,10 @@ inline void CheckNewUpdate() { if (current_version != latest_version) { CLI_LOG("\nA new release of cortex is available: " << current_version << " -> " << latest_version); - CLI_LOG("To upgrade, run: cortex update"); - // CLI_LOG(json_res["html_url"].get()); + CLI_LOG("To upgrade, run: " << GetCortexBinary() << " update"); + if (CORTEX_VARIANT == file_manager_utils::kProdVariant) { + CLI_LOG(json_res["html_url"].get()); + } } } catch (const nlohmann::json::parse_error& e) { CTL_INF("JSON parse error: " << e.what()); @@ -83,7 +85,7 @@ inline bool ReplaceBinaryInflight(const std::filesystem::path& src, // Already has the newest return true; } - std::filesystem::path temp = std::filesystem::temp_directory_path() / "cortex_temp"; + std::filesystem::path temp = dst.parent_path() / "cortex_temp"; try { if (std::filesystem::exists(temp)) { @@ -97,8 +99,6 @@ inline bool ReplaceBinaryInflight(const std::filesystem::path& src, std::filesystem::perms::group_all | std::filesystem::perms::others_read | std::filesystem::perms::others_exec); - auto download_folder = src.parent_path(); - std::filesystem::remove_all(download_folder); } catch (const std::exception& e) { CTL_ERR("Something wrong happened: " << e.what()); if (std::filesystem::exists(temp)) { diff --git a/engine/e2e-test/main.py b/engine/e2e-test/main.py index 9ef27c8dc..d6af1522c 100644 --- a/engine/e2e-test/main.py +++ b/engine/e2e-test/main.py @@ -4,6 +4,7 @@ from test_cli_engine_install import TestCliEngineInstall from test_cli_engine_list import TestCliEngineList from test_cli_engine_uninstall import TestCliEngineUninstall +from test_cortex_update import TestCortexUpdate from test_cli_server_start import TestCliServerStart from test_create_log_folder import TestCreateLogFolder diff --git a/engine/e2e-test/test_cortex_update.py b/engine/e2e-test/test_cortex_update.py new file mode 100644 index 000000000..fc1fe25cb --- /dev/null +++ b/engine/e2e-test/test_cortex_update.py @@ -0,0 +1,14 @@ +import platform + +import pytest +from test_runner import run + + +class TestCortexUpdate: + # We don't have stable release yet, so mark this test as skip for now + # Only able to test with beta and nightly + @pytest.mark.skip(reason="Stable release is not available yet") + def test_cortex_update(self): + exit_code, output, error = run("Update cortex", ["update"]) + assert exit_code == 0, f"Something wrong happened" + assert "Update cortex sucessfully" in output diff --git a/engine/main.cc b/engine/main.cc index 38dd3791b..cf123e16a 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -9,6 +9,7 @@ #include "utils/file_logger.h" #include "utils/file_manager_utils.h" #include "utils/logging_utils.h" +#include "commands/cortex_upd_cmd.h" #if defined(__APPLE__) && defined(__MACH__) #include // for dirname() @@ -91,8 +92,9 @@ void ForkProcess() { ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); + auto exe = commands::GetCortexBinary(); std::string cmds = - cortex_utils::GetCurrentPath() + "/cortex-cpp.exe --start-server"; + cortex_utils::GetCurrentPath() + "/" + exe + " --start-server"; // Create child process if (!CreateProcess( NULL, // No module name (use command line) @@ -133,6 +135,17 @@ void ForkProcess() { int main(int argc, char* argv[]) { { file_manager_utils::CreateConfigFileIfNotExist(); } + // Delete temporary file if it exists + auto temp = + file_manager_utils::GetExecutableFolderContainerPath() / "cortex_temp"; + if (std::filesystem::exists(temp)) { + try { + std::filesystem::remove(temp); + } catch (const std::exception& e) { + std::cerr << e.what() << '\n'; + } + } + // Check if this process is for python execution if (argc > 1) { if (strcmp(argv[1], "--run_python_file") == 0) { diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index b4d7ab07a..1e5c522e0 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -230,7 +230,7 @@ inline std::filesystem::path GetContainerFolderPath( } else if (type == "CudaToolkit") { container_folder_path = current_path; } else if (type == "Cortex") { - container_folder_path = current_path / "cortex"; + container_folder_path = std::filesystem::temp_directory_path() / "cortex"; } else { container_folder_path = current_path / "misc"; }