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

Commit 8b9f6f4

Browse files
fix: correct get server name method (#1953)
Co-authored-by: vansangpfiev <[email protected]>
1 parent cdb2446 commit 8b9f6f4

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

engine/services/hardware_service.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ bool HardwareService::Restart(const std::string& host, int port) {
6060
namespace luh = logging_utils_helper;
6161
if (!ahc_)
6262
return true;
63-
auto exe = commands::GetCortexServerBinary();
63+
auto exe = file_manager_utils::Subtract(
64+
file_manager_utils::GetExecutablePath(), cortex_utils::GetCurrentPath());
6465
auto get_config_file_path = []() -> std::string {
6566
if (file_manager_utils::cortex_config_file_path.empty()) {
6667
return file_manager_utils::GetConfigurationPath().string();
@@ -147,10 +148,11 @@ bool HardwareService::Restart(const std::string& host, int port) {
147148
file_manager_utils::GetCortexDataPath().wstring();
148149
params += L" --loglevel " +
149150
cortex::wc::Utf8ToWstring(luh::LogLevelStr(luh::global_log_level));
150-
std::wstring exe_w = cortex::wc::Utf8ToWstring(exe);
151+
std::wstring exe_w = exe.wstring();
151152
std::wstring current_path_w =
152153
file_manager_utils::GetExecutableFolderContainerPath().wstring();
153154
std::wstring wcmds = current_path_w + L"/" + exe_w + L" " + params;
155+
CTL_DBG("wcmds: " << wcmds);
154156
std::vector<wchar_t> mutable_cmds(wcmds.begin(), wcmds.end());
155157
mutable_cmds.push_back(L'\0');
156158
// Create child process
@@ -200,7 +202,8 @@ bool HardwareService::Restart(const std::string& host, int port) {
200202
setenv(name, new_v.c_str(), true);
201203
CTL_INF("LD_LIBRARY_PATH: " << getenv(name));
202204
#endif
203-
std::string p = cortex_utils::GetCurrentPath() + "/" + exe;
205+
std::string p = cortex_utils::GetCurrentPath() + "/" + exe.string();
206+
CTL_INF("server file path: " << p);
204207
execl(p.c_str(), exe.c_str(), "--ignore_cout", "--config_file_path",
205208
get_config_file_path().c_str(), "--data_folder_path",
206209
get_data_folder_path().c_str(), "--loglevel",

engine/utils/file_manager_utils.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
#endif
1818

1919
namespace file_manager_utils {
20-
std::filesystem::path GetExecutableFolderContainerPath() {
20+
21+
std::filesystem::path GetExecutablePath() {
2122
#if defined(__APPLE__) && defined(__MACH__)
2223
char buffer[1024];
2324
uint32_t size = sizeof(buffer);
2425

2526
if (_NSGetExecutablePath(buffer, &size) == 0) {
2627
// CTL_DBG("Executable path: " << buffer);
27-
return std::filesystem::path{buffer}.parent_path();
28+
return std::filesystem::path{buffer};
2829
} else {
2930
CTL_ERR("Failed to get executable path");
3031
return std::filesystem::current_path();
@@ -35,7 +36,7 @@ std::filesystem::path GetExecutableFolderContainerPath() {
3536
if (len != -1) {
3637
buffer[len] = '\0';
3738
// CTL_DBG("Executable path: " << buffer);
38-
return std::filesystem::path{buffer}.parent_path();
39+
return std::filesystem::path{buffer};
3940
} else {
4041
CTL_ERR("Failed to get executable path");
4142
return std::filesystem::current_path();
@@ -44,13 +45,17 @@ std::filesystem::path GetExecutableFolderContainerPath() {
4445
wchar_t buffer[MAX_PATH];
4546
GetModuleFileNameW(NULL, buffer, MAX_PATH);
4647
// CTL_DBG("Executable path: " << buffer);
47-
return std::filesystem::path{buffer}.parent_path();
48+
return std::filesystem::path{buffer};
4849
#else
4950
LOG_ERROR << "Unsupported platform!";
5051
return std::filesystem::current_path();
5152
#endif
5253
}
5354

55+
std::filesystem::path GetExecutableFolderContainerPath() {
56+
return GetExecutablePath().parent_path();
57+
}
58+
5459
std::filesystem::path GetHomeDirectoryPath() {
5560
#ifdef _WIN32
5661
const wchar_t* homeDir = _wgetenv(L"USERPROFILE");

engine/utils/file_manager_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ inline std::string cortex_config_file_path;
2020

2121
inline std::string cortex_data_folder_path;
2222

23+
std::filesystem::path GetExecutablePath();
24+
2325
std::filesystem::path GetExecutableFolderContainerPath();
2426

2527
std::filesystem::path GetHomeDirectoryPath();

0 commit comments

Comments
 (0)