Skip to content

Commit

Permalink
fix: use temp directory for cortex_temp binary
Browse files Browse the repository at this point in the history
  • Loading branch information
vansangpfiev committed Sep 10, 2024
1 parent 69d52b2 commit 1d3a54c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 1 addition & 2 deletions engine/commands/cortex_upd_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ inline bool ReplaceBinaryInflight(const std::filesystem::path& src,
// Already has the newest
return true;
}
std::filesystem::path temp = dst.parent_path() / "cortex_temp";
std::cout << temp.string() << std::endl;
std::filesystem::path temp = std::filesystem::temp_directory_path() / "cortex_temp";

try {
if (std::filesystem::exists(temp)) {
Expand Down
12 changes: 7 additions & 5 deletions engine/test/components/test_cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace {
constexpr const auto kNewReleaseFolder = "./cortex-release";
constexpr const auto kNewReleaseFile = "./cortex-release/cortexexe";
constexpr const auto kCurReleaseFile = "./cortexexe";
constexpr const auto kTemp = "./cortex_temp";
std::filesystem::path GetCortexTemp() {
return std::filesystem::temp_directory_path() / "cortex_temp";
}
} // namespace

class CortexUpdCmdTest : public ::testing::Test {
Expand All @@ -29,8 +31,8 @@ class CortexUpdCmdTest : public ::testing::Test {
std::filesystem::remove(kCurReleaseFile);
}

if (std::filesystem::exists(kTemp)) {
std::filesystem::remove(kTemp);
if (std::filesystem::exists(GetCortexTemp())) {
std::filesystem::remove(GetCortexTemp());
}
}
};
Expand All @@ -43,12 +45,12 @@ TEST_F(CortexUpdCmdTest, replace_binary_successfully) {
std::filesystem::path new_binary(kNewReleaseFile);
std::filesystem::path cur_binary(kCurReleaseFile);
EXPECT_TRUE(commands::ReplaceBinaryInflight(new_binary, cur_binary));
EXPECT_TRUE(std::filesystem::exists(kTemp));
EXPECT_TRUE(std::filesystem::exists(GetCortexTemp()));
}

TEST_F(CortexUpdCmdTest, should_restore_old_binary_if_has_error) {
std::filesystem::path new_binary("Non-exist");
std::filesystem::path cur_binary(kCurReleaseFile);
EXPECT_FALSE(commands::ReplaceBinaryInflight(new_binary, cur_binary));
EXPECT_FALSE(std::filesystem::exists(kTemp));
EXPECT_FALSE(std::filesystem::exists(GetCortexTemp()));
}

0 comments on commit 1d3a54c

Please sign in to comment.