Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vansangpfiev committed Sep 6, 2024
1 parent c9ffefe commit 00bc507
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 22 additions & 16 deletions engine/commands/cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const std::string kCortexBinary = "cortex-cpp";
CortexUpdCmd::CortexUpdCmd() {}

void CortexUpdCmd::Exec(std::string v) {
// TODO(sang) stop server if it is running
// Check if the architecture and OS are supported
auto system_info = system_info_utils::GetSystemInfo();
if (system_info.arch == system_info_utils::kUnsupported ||
Expand Down Expand Up @@ -127,25 +128,29 @@ void CortexUpdCmd::Exec(std::string v) {
return;
}
#if defined(_WIN32)
std::string temp = ".\\cortex_tmp.exe";
remove(temp.c_str()); // ignore return code
auto executable_path = file_manager_utils::GetExecutableFolderContainerPath();
auto temp = executable_path / "cortex_tmp.exe";
remove(temp.string().c_str()); // ignore return code

std::string src =
".\\cortex\\" + kCortexBinary + "\\" + kCortexBinary + ".exe";
std::string dst = ".\\" + kCortexBinary + ".exe";
auto src =
executable_path / "cortex" / kCortexBinary / (kCortexBinary + ".exe");
auto dst = executable_path / (kCortexBinary + ".exe");
// Rename
rename(dst.c_str(), temp.c_str());
rename(dst.string().c_str(), temp.string().c_str());
// Update
CopyFile(const_cast<char*>(src.c_str()), const_cast<char*>(dst.c_str()),
false);
remove(".\\cortex");
remove(temp.c_str());
CopyFile(const_cast<char*>(src.string().c_str()),
const_cast<char*>(dst.string().c_str()), false);
auto download_folder = executable_path / "cortex";
remove(download_folder);
remove(temp.string().c_str());
#else
std::string temp = "./cortex_tmp";
std::string src = "./cortex/" + kCortexBinary + "/" + kCortexBinary;
std::string dst = "./" + kCortexBinary;
if (std::rename(dst.c_str(), temp.c_str())) {
CTL_ERR("Failed to rename from " << dst << " to " << temp);
auto executable_path = file_manager_utils::GetExecutableFolderContainerPath();
auto temp = executable_path / "cortex_tmp";
auto src = executable_path / "cortex" / kCortexBinary / kCortexBinary;
auto dst = executable_path / kCortexBinary;
if (std::rename(dst.string().c_str(), temp.string().c_str())) {
CTL_ERR("Failed to rename from " << dst.string() << " to "
<< temp.string());
return;
}
try {
Expand All @@ -156,7 +161,8 @@ void CortexUpdCmd::Exec(std::string v) {
std::filesystem::perms::others_read |
std::filesystem::perms::others_exec);
std::filesystem::remove(temp);
std::filesystem::remove_all("./cortex/");
auto download_folder = executable_path / "cortex/";
std::filesystem::remove_all(download_folder);
} catch (const std::exception& e) {
CTL_WRN("Something wrong happened: " << e.what());
return;
Expand Down
2 changes: 0 additions & 2 deletions engine/commands/cortex_upd_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class CortexUpdCmd{
public:
CortexUpdCmd();
void Exec(std::string version);

private:
};

} // namespace commands

0 comments on commit 00bc507

Please sign in to comment.