From 94c9b3d05177f1b05403d2d72c5a3c6cb94eae7f Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 6 Sep 2024 12:08:19 +0700 Subject: [PATCH 1/5] fix: correct path to work with data folder structure --- engine/commands/model_get_cmd.cc | 12 +++--- engine/commands/model_list_cmd.cc | 13 +++--- engine/commands/run_cmd.cc | 20 +++++---- engine/controllers/command_line_parser.cc | 16 ++++--- engine/controllers/models.cc | 10 +++-- engine/controllers/server.cc | 4 +- engine/main.cc | 6 +-- engine/utils/config_yaml_utils.h | 28 ++---------- engine/utils/file_manager_utils.h | 52 ++++++++++++++++++----- 9 files changed, 93 insertions(+), 68 deletions(-) diff --git a/engine/commands/model_get_cmd.cc b/engine/commands/model_get_cmd.cc index cc6639d33..6e531201b 100644 --- a/engine/commands/model_get_cmd.cc +++ b/engine/commands/model_get_cmd.cc @@ -6,6 +6,7 @@ #include "config/yaml_config.h" #include "trantor/utils/Logger.h" #include "utils/cortex_utils.h" +#include "utils/file_manager_utils.h" #include "utils/logging_utils.h" namespace commands { @@ -14,15 +15,16 @@ ModelGetCmd::ModelGetCmd(std::string model_handle) : model_handle_(std::move(model_handle)) {} void ModelGetCmd::Exec() { - if (std::filesystem::exists(cortex_utils::models_folder) && - std::filesystem::is_directory(cortex_utils::models_folder)) { + std::filesystem::path models_path = + file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder; + if (std::filesystem::exists(models_path) && + std::filesystem::is_directory(models_path)) { CmdInfo ci(model_handle_); std::string model_file = ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; bool found_model = false; // Iterate through directory - for (const auto& entry : - std::filesystem::directory_iterator(cortex_utils::models_folder)) { + for (const auto& entry : std::filesystem::directory_iterator(models_path)) { if (entry.is_regular_file() && entry.path().stem() == model_file && entry.path().extension() == ".yaml") { @@ -137,7 +139,7 @@ void ModelGetCmd::Exec() { break; } catch (const std::exception& e) { CTL_ERR("Error reading yaml file '" << entry.path().string() - << "': " << e.what()); + << "': " << e.what()); } } } diff --git a/engine/commands/model_list_cmd.cc b/engine/commands/model_list_cmd.cc index c2a04f06f..dcf6cf6eb 100644 --- a/engine/commands/model_list_cmd.cc +++ b/engine/commands/model_list_cmd.cc @@ -8,20 +8,23 @@ #include #include "config/yaml_config.h" #include "trantor/utils/Logger.h" +#include "utils/file_manager_utils.h" #include "utils/logging_utils.h" + namespace commands { void ModelListCmd::Exec() { - if (std::filesystem::exists(cortex_utils::models_folder) && - std::filesystem::is_directory(cortex_utils::models_folder)) { + std::filesystem::path models_path = + file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder; + if (std::filesystem::exists(models_path) && + std::filesystem::is_directory(models_path)) { tabulate::Table table; table.add_row({"(Index)", "ID", "engine", "version"}); table.format().font_color(tabulate::Color::green); int count = 0; // Iterate through directory - for (const auto& entry : - std::filesystem::directory_iterator(cortex_utils::models_folder)) { + for (const auto& entry : std::filesystem::directory_iterator(models_path)) { if (entry.is_regular_file() && entry.path().extension() == ".yaml") { try { count += 1; @@ -32,7 +35,7 @@ void ModelListCmd::Exec() { model_config.engine, model_config.version}); } catch (const std::exception& e) { CTL_ERR("Error reading yaml file '" << entry.path().string() - << "': " << e.what()); + << "': " << e.what()); } } } diff --git a/engine/commands/run_cmd.cc b/engine/commands/run_cmd.cc index 5070c3937..a292d77a7 100644 --- a/engine/commands/run_cmd.cc +++ b/engine/commands/run_cmd.cc @@ -7,6 +7,7 @@ #include "model_start_cmd.h" #include "trantor/utils/Logger.h" #include "utils/cortex_utils.h" +#include "utils/file_manager_utils.h" namespace commands { @@ -42,8 +43,9 @@ void RunCmd::Exec() { // Start model config::YamlHandler yaml_handler; - yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + "/models/" + - model_file + ".yaml"); + yaml_handler.ModelConfigFromFile( + file_manager_utils::GetCortexDataPath().string() + + cortex_utils::models_folder + model_file + ".yaml"); { ModelStartCmd msc(host_, port_, yaml_handler.GetModelConfig()); if (!msc.Exec()) { @@ -59,13 +61,13 @@ void RunCmd::Exec() { } bool RunCmd::IsModelExisted(const std::string& model_id) { - if (std::filesystem::exists(cortex_utils::GetCurrentPath() + "/" + + if (std::filesystem::exists(file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder) && - std::filesystem::is_directory(cortex_utils::GetCurrentPath() + "/" + + std::filesystem::is_directory(file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder)) { // Iterate through directory for (const auto& entry : std::filesystem::directory_iterator( - cortex_utils::GetCurrentPath() + "/" + + file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder)) { if (entry.is_regular_file() && entry.path().extension() == ".yaml") { try { @@ -85,10 +87,10 @@ bool RunCmd::IsModelExisted(const std::string& model_id) { } bool RunCmd::IsEngineExisted(const std::string& e) { - if (std::filesystem::exists(cortex_utils::GetCurrentPath() + "/" + - "engines") && - std::filesystem::exists(cortex_utils::GetCurrentPath() + "/" + - "engines/" + e)) { + if (std::filesystem::exists(file_manager_utils::GetCortexDataPath().string() + + "/" + "engines") && + std::filesystem::exists(file_manager_utils::GetCortexDataPath().string() + + "/" + "engines/" + e)) { return true; } return false; diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index 8c8c706a3..ff92cc0a4 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -17,6 +17,7 @@ #include "httplib.h" #include "services/engine_service.h" #include "utils/cortex_utils.h" +#include "utils/file_manager_utils.h" #include "utils/logging_utils.h" CommandLineParser::CommandLineParser() @@ -38,8 +39,9 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { std::string model_file = ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; - yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + - "/models/" + model_file + ".yaml"); + yaml_handler.ModelConfigFromFile( + file_manager_utils::GetCortexDataPath().string() + "/models/" + + model_file + ".yaml"); commands::ModelStartCmd msc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); msc.Exec(); @@ -53,8 +55,9 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { std::string model_file = ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; - yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + - "/models/" + model_file + ".yaml"); + yaml_handler.ModelConfigFromFile( + file_manager_utils::GetCortexDataPath().string() + "/models/" + + model_file + ".yaml"); commands::ModelStopCmd smc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); smc.Exec(); @@ -107,8 +110,9 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { std::string model_file = ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; - yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + - "/models/" + model_file + ".yaml"); + yaml_handler.ModelConfigFromFile( + file_manager_utils::GetCortexDataPath().string() + "/models/" + + model_file + ".yaml"); commands::ChatCmd cc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); cc.Exec(msg); }); diff --git a/engine/controllers/models.cc b/engine/controllers/models.cc index 52a8bff28..d669dce14 100644 --- a/engine/controllers/models.cc +++ b/engine/controllers/models.cc @@ -2,6 +2,7 @@ #include "config/yaml_config.h" #include "trantor/utils/Logger.h" #include "utils/cortex_utils.h" +#include "utils/file_manager_utils.h" #include "utils/model_callback_utils.h" void Models::PullModel( @@ -49,11 +50,12 @@ void Models::ListModel( Json::Value ret; ret["object"] = "list"; Json::Value data(Json::arrayValue); - if (std::filesystem::exists(cortex_utils::models_folder) && - std::filesystem::is_directory(cortex_utils::models_folder)) { + std::filesystem::path models_path = + file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder; + if (std::filesystem::exists(models_path) && + std::filesystem::is_directory(models_path)) { // Iterate through directory - for (const auto& entry : - std::filesystem::directory_iterator(cortex_utils::models_folder)) { + for (const auto& entry : std::filesystem::directory_iterator(models_path)) { if (entry.is_regular_file() && entry.path().extension() == ".yaml") { try { config::YamlHandler handler; diff --git a/engine/controllers/server.cc b/engine/controllers/server.cc index 0c5963d7a..42a7595be 100644 --- a/engine/controllers/server.cc +++ b/engine/controllers/server.cc @@ -8,6 +8,7 @@ #include "utils/cortex_utils.h" #include "utils/cpuid/cpu_info.h" #include "utils/logging_utils.h" +#include "utils/file_manager_utils.h" using namespace inferences; using json = nlohmann::json; @@ -290,8 +291,9 @@ void server::LoadModel(const HttpRequestPtr& req, std::string abs_path = (getenv("ENGINE_PATH") ? getenv("ENGINE_PATH") - : cortex_utils::GetCurrentPath()) + + : file_manager_utils::GetCortexDataPath().string()) + get_engine_path(engine_type); + std::cout << abs_path << std::endl; engines_[engine_type].dl = std::make_unique(abs_path, "engine"); diff --git a/engine/main.cc b/engine/main.cc index 79e8b656e..d705e7633 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -4,7 +4,7 @@ #include "controllers/command_line_parser.h" #include "cortex-common/cortexpythoni.h" #include "utils/archive_utils.h" -#include "utils/config_yaml_utils.h" +// #include "utils/config_yaml_utils.h" #include "utils/cortex_utils.h" #include "utils/dylib.h" #include "utils/file_manager_utils.h" @@ -26,7 +26,7 @@ #endif void RunServer() { - auto config = config_yaml_utils::GetCortexConfig(); + auto config = file_manager_utils::GetCortexConfig(); LOG_INFO << "Host: " << config.host << " Port: " << config.port << "\n"; // Create logs/ folder and setup log to file @@ -127,7 +127,7 @@ void ForkProcess() { } int main(int argc, char* argv[]) { - { config_yaml_utils::CreateConfigFileIfNotExist(); } + { file_manager_utils::CreateConfigFileIfNotExist(); } // Check if this process is for python execution if (argc > 1) { diff --git a/engine/utils/config_yaml_utils.h b/engine/utils/config_yaml_utils.h index 75abfca0b..59b2b666e 100644 --- a/engine/utils/config_yaml_utils.h +++ b/engine/utils/config_yaml_utils.h @@ -1,8 +1,8 @@ +#pragma once #include #include #include #include -#include "utils/file_manager_utils.h" #include "utils/logging_utils.h" #include "yaml-cpp/yaml.h" @@ -13,7 +13,7 @@ struct CortexConfig { std::string port; }; -const std::string kCortexFolderName = "cortexcpp"; +const std::string kCortexFolderName = ".cortexcpp"; const std::string kDefaultHost{"127.0.0.1"}; const std::string kDefaultPort{"3928"}; @@ -39,24 +39,6 @@ inline void DumpYamlConfig(const CortexConfig& config, } } -inline void CreateConfigFileIfNotExist() { - auto config_path = file_manager_utils::GetConfigurationPath(); - if (std::filesystem::exists(config_path)) { - // already exists - return; - } - CLI_LOG("Config file not found. Creating one at " + config_path.string()); - auto defaultDataFolderPath = - file_manager_utils::GetHomeDirectoryPath() / kCortexFolderName; - auto config = CortexConfig{ - .dataFolderPath = defaultDataFolderPath.string(), - .host = kDefaultHost, - .port = kDefaultPort, - }; - std::cout << "config: " << config.dataFolderPath << "\n"; - DumpYamlConfig(config, config_path.string()); -} - inline CortexConfig FromYaml(const std::string& path, const std::string& variant) { std::filesystem::path config_file_path{path}; @@ -78,9 +60,5 @@ inline CortexConfig FromYaml(const std::string& path, } } -inline CortexConfig GetCortexConfig() { - auto config_path = file_manager_utils::GetConfigurationPath(); - std::string variant = ""; // TODO: empty for now - return FromYaml(config_path.string(), variant); -} + } // namespace config_yaml_utils diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index fd2723078..223ab6f4f 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -4,6 +4,7 @@ #include #include "logging_utils.h" #include "services/download_service.h" +#include "utils/config_yaml_utils.h" #if defined(__APPLE__) && defined(__MACH__) #include @@ -84,23 +85,54 @@ inline std::filesystem::path GetConfigurationPath() { return configuration_path; } -inline std::filesystem::path GetCortexPath() { +inline void CreateConfigFileIfNotExist() { + auto config_path = file_manager_utils::GetConfigurationPath(); + if (std::filesystem::exists(config_path)) { + // already exists + return; + } + CLI_LOG("Config file not found. Creating one at " + config_path.string()); + auto defaultDataFolderPath = + file_manager_utils::GetHomeDirectoryPath() / config_yaml_utils::kCortexFolderName; + auto config = config_yaml_utils::CortexConfig{ + .dataFolderPath = defaultDataFolderPath.string(), + .host = config_yaml_utils::kDefaultHost, + .port = config_yaml_utils::kDefaultPort, + }; + std::cout << "config: " << config.dataFolderPath << "\n"; + DumpYamlConfig(config, config_path.string()); +} + +inline config_yaml_utils::CortexConfig GetCortexConfig() { + auto config_path = GetConfigurationPath(); + std::string variant = ""; // TODO: empty for now + return config_yaml_utils::FromYaml(config_path.string(), variant); +} + +inline std::filesystem::path GetCortexDataPath() { // TODO: We will need to support user to move the data folder to other place. // TODO: get the variant of cortex. As discussed, we will have: prod, beta, nightly - // currently we will store cortex data at ~/.cortex + // currently we will store cortex data at ~/.cortexcpp + auto config = GetCortexConfig(); + std::filesystem::path data_folder_path; + if (!config.dataFolderPath.empty()) { + data_folder_path = + std::filesystem::path(config.dataFolderPath) / ".cortexcpp"; + } else { + auto home_path = GetHomeDirectoryPath(); + data_folder_path = home_path / ".cortexcpp"; + } - auto home_path = GetHomeDirectoryPath(); - auto cortex_path = home_path / ".cortex"; - if (!std::filesystem::exists(cortex_path)) { + if (!std::filesystem::exists(data_folder_path)) { CTL_INF("Cortex home folder not found. Create one: " + - cortex_path.string()); - std::filesystem::create_directory(cortex_path); + data_folder_path.string()); + std::filesystem::create_directory(data_folder_path); } - return cortex_path; + return data_folder_path; } inline std::filesystem::path GetModelsContainerPath() { - auto cortex_path = GetCortexPath(); + auto cortex_path = GetCortexDataPath(); auto models_container_path = cortex_path / "models"; if (!std::filesystem::exists(models_container_path)) { @@ -113,7 +145,7 @@ inline std::filesystem::path GetModelsContainerPath() { } inline std::filesystem::path GetEnginesContainerPath() { - auto cortex_path = GetCortexPath(); + auto cortex_path = GetCortexDataPath(); auto engines_container_path = cortex_path / "engines"; if (!std::filesystem::exists(engines_container_path)) { From da183ccc93d8a440c7b30109883066a5cd94346d Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 6 Sep 2024 13:09:52 +0700 Subject: [PATCH 2/5] fix: clean --- engine/commands/model_get_cmd.cc | 3 +-- engine/commands/model_list_cmd.cc | 3 +-- engine/commands/run_cmd.cc | 22 +++++++++------------- engine/controllers/command_line_parser.cc | 6 +++--- engine/controllers/models.cc | 3 +-- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/engine/commands/model_get_cmd.cc b/engine/commands/model_get_cmd.cc index 6e531201b..acbce742c 100644 --- a/engine/commands/model_get_cmd.cc +++ b/engine/commands/model_get_cmd.cc @@ -15,8 +15,7 @@ ModelGetCmd::ModelGetCmd(std::string model_handle) : model_handle_(std::move(model_handle)) {} void ModelGetCmd::Exec() { - std::filesystem::path models_path = - file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder; + auto models_path = file_manager_utils::GetModelsContainerPath(); if (std::filesystem::exists(models_path) && std::filesystem::is_directory(models_path)) { CmdInfo ci(model_handle_); diff --git a/engine/commands/model_list_cmd.cc b/engine/commands/model_list_cmd.cc index dcf6cf6eb..70d1e79ea 100644 --- a/engine/commands/model_list_cmd.cc +++ b/engine/commands/model_list_cmd.cc @@ -14,8 +14,7 @@ namespace commands { void ModelListCmd::Exec() { - std::filesystem::path models_path = - file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder; + auto models_path = file_manager_utils::GetModelsContainerPath(); if (std::filesystem::exists(models_path) && std::filesystem::is_directory(models_path)) { tabulate::Table table; diff --git a/engine/commands/run_cmd.cc b/engine/commands/run_cmd.cc index a292d77a7..c8bde1b14 100644 --- a/engine/commands/run_cmd.cc +++ b/engine/commands/run_cmd.cc @@ -44,8 +44,8 @@ void RunCmd::Exec() { // Start model config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile( - file_manager_utils::GetCortexDataPath().string() + - cortex_utils::models_folder + model_file + ".yaml"); + file_manager_utils::GetModelsContainerPath().string() + "/" + model_file + + ".yaml"); { ModelStartCmd msc(host_, port_, yaml_handler.GetModelConfig()); if (!msc.Exec()) { @@ -61,14 +61,11 @@ void RunCmd::Exec() { } bool RunCmd::IsModelExisted(const std::string& model_id) { - if (std::filesystem::exists(file_manager_utils::GetCortexDataPath() / - cortex_utils::models_folder) && - std::filesystem::is_directory(file_manager_utils::GetCortexDataPath() / - cortex_utils::models_folder)) { + auto models_path = file_manager_utils::GetModelsContainerPath(); + if (std::filesystem::exists(models_path) && + std::filesystem::is_directory(models_path)) { // Iterate through directory - for (const auto& entry : std::filesystem::directory_iterator( - file_manager_utils::GetCortexDataPath() / - cortex_utils::models_folder)) { + for (const auto& entry : std::filesystem::directory_iterator(models_path)) { if (entry.is_regular_file() && entry.path().extension() == ".yaml") { try { config::YamlHandler handler; @@ -87,10 +84,9 @@ bool RunCmd::IsModelExisted(const std::string& model_id) { } bool RunCmd::IsEngineExisted(const std::string& e) { - if (std::filesystem::exists(file_manager_utils::GetCortexDataPath().string() + - "/" + "engines") && - std::filesystem::exists(file_manager_utils::GetCortexDataPath().string() + - "/" + "engines/" + e)) { + auto engines_path = file_manager_utils::GetEnginesContainerPath(); + if (std::filesystem::exists(engines_path) && + std::filesystem::exists(engines_path.string() + "/" + e)) { return true; } return false; diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index ff92cc0a4..b8ad72f58 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -40,7 +40,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile( - file_manager_utils::GetCortexDataPath().string() + "/models/" + + file_manager_utils::GetModelsContainerPath().string() + "/" + model_file + ".yaml"); commands::ModelStartCmd msc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); @@ -56,7 +56,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile( - file_manager_utils::GetCortexDataPath().string() + "/models/" + + file_manager_utils::GetModelsContainerPath().string() + "/" + model_file + ".yaml"); commands::ModelStopCmd smc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); @@ -111,7 +111,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile( - file_manager_utils::GetCortexDataPath().string() + "/models/" + + file_manager_utils::GetModelsContainerPath().string() + "/" + model_file + ".yaml"); commands::ChatCmd cc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); cc.Exec(msg); diff --git a/engine/controllers/models.cc b/engine/controllers/models.cc index d669dce14..e4b6f4adc 100644 --- a/engine/controllers/models.cc +++ b/engine/controllers/models.cc @@ -50,8 +50,7 @@ void Models::ListModel( Json::Value ret; ret["object"] = "list"; Json::Value data(Json::arrayValue); - std::filesystem::path models_path = - file_manager_utils::GetCortexDataPath() / cortex_utils::models_folder; + auto models_path = file_manager_utils::GetModelsContainerPath(); if (std::filesystem::exists(models_path) && std::filesystem::is_directory(models_path)) { // Iterate through directory From bf4f6fdec42834c8e6aedbfeaeff4a180cfd7c51 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 6 Sep 2024 13:42:48 +0700 Subject: [PATCH 3/5] fix: comments --- engine/utils/config_yaml_utils.h | 2 +- engine/utils/file_manager_utils.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/utils/config_yaml_utils.h b/engine/utils/config_yaml_utils.h index 59b2b666e..4330f3527 100644 --- a/engine/utils/config_yaml_utils.h +++ b/engine/utils/config_yaml_utils.h @@ -13,7 +13,7 @@ struct CortexConfig { std::string port; }; -const std::string kCortexFolderName = ".cortexcpp"; +const std::string kCortexFolderName = "cortexcpp"; const std::string kDefaultHost{"127.0.0.1"}; const std::string kDefaultPort{"3928"}; diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index 223ab6f4f..c0a84db8e 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -15,7 +15,7 @@ #endif namespace file_manager_utils { -constexpr std::string_view kCortexConfigurationFileName = ".cortexrc"; +constexpr std::string_view kCortexConfigurationFileName = "cortexrc"; constexpr std::string_view kDefaultConfigurationPath = "user_home"; inline std::filesystem::path GetExecutableFolderContainerPath() { @@ -112,15 +112,15 @@ inline config_yaml_utils::CortexConfig GetCortexConfig() { inline std::filesystem::path GetCortexDataPath() { // TODO: We will need to support user to move the data folder to other place. // TODO: get the variant of cortex. As discussed, we will have: prod, beta, nightly - // currently we will store cortex data at ~/.cortexcpp + // currently we will store cortex data at ~/cortexcpp auto config = GetCortexConfig(); std::filesystem::path data_folder_path; if (!config.dataFolderPath.empty()) { data_folder_path = - std::filesystem::path(config.dataFolderPath) / ".cortexcpp"; + std::filesystem::path(config.dataFolderPath); } else { auto home_path = GetHomeDirectoryPath(); - data_folder_path = home_path / ".cortexcpp"; + data_folder_path = home_path / config_yaml_utils::kCortexFolderName; } if (!std::filesystem::exists(data_folder_path)) { From f0bdf584e47231476d3bcfceb034bdeb069638f0 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 6 Sep 2024 13:52:35 +0700 Subject: [PATCH 4/5] fix: hide cortexrc --- engine/utils/file_manager_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index c0a84db8e..fcf8a959a 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -15,7 +15,7 @@ #endif namespace file_manager_utils { -constexpr std::string_view kCortexConfigurationFileName = "cortexrc"; +constexpr std::string_view kCortexConfigurationFileName = ".cortexrc"; constexpr std::string_view kDefaultConfigurationPath = "user_home"; inline std::filesystem::path GetExecutableFolderContainerPath() { From 7bf7c020e255b25ecfe45f35913869512e65e118 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 6 Sep 2024 13:54:15 +0700 Subject: [PATCH 5/5] fix: remove unused --- engine/main.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/main.cc b/engine/main.cc index d705e7633..5c83d1103 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -4,7 +4,6 @@ #include "controllers/command_line_parser.h" #include "cortex-common/cortexpythoni.h" #include "utils/archive_utils.h" -// #include "utils/config_yaml_utils.h" #include "utils/cortex_utils.h" #include "utils/dylib.h" #include "utils/file_manager_utils.h"