From a634a12bfc8773ca8b66a5f2fd99d2c705a4fc21 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 29 May 2025 22:43:41 +1200 Subject: [PATCH] :-'Generic Commit' --- src/main.cpp | 30 +++++++++++++++++++++++------- test.sh.downloaded1 | 1 + test.sh.downloaded2 | 1 + 3 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 test.sh.downloaded1 create mode 100644 test.sh.downloaded2 diff --git a/src/main.cpp b/src/main.cpp index 7df8f4e..59102ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,14 +14,30 @@ std::atomic g_running{true}; std::unique_ptr g_server; std::thread g_server_thread; -std::filesystem::path get_config_path() { - std::filesystem::path system_config_path = "/data/sos_config.json"; - std::filesystem::path user_config_path = std::filesystem::path(std::getenv("HOME")) / ".config/simple_object_storage/config.json"; +std::filesystem::path get_executable_path() { + return std::filesystem::read_symlink("/proc/self/exe"); +} - if (std::filesystem::exists(system_config_path)) return system_config_path; - if (std::filesystem::exists(user_config_path)) return user_config_path; - - std::cout << "No config file found. Checked " << system_config_path << " and " << user_config_path << std::endl; +std::filesystem::path get_config_path() { + const std::filesystem::path _home = std::getenv("HOME"); + const std::filesystem::path _exe = get_executable_path().parent_path(); + + // check for config in the following paths: + std::vector config_paths = { + "/data/sos_config.json", + _home / ".config/simple_object_storage/config.json", + _exe / ".." / ".test-docker" / "config.json" + }; + + for (const auto& path : config_paths) { + if (std::filesystem::exists(path)) { + return path; + } + } + std::cout << "No config file found. Checked: " << std::endl; + for (const auto& path : config_paths) { + std::cout << " " << path << std::endl; + } return std::filesystem::path(); } diff --git a/test.sh.downloaded1 b/test.sh.downloaded1 new file mode 100644 index 0000000..4fc1017 --- /dev/null +++ b/test.sh.downloaded1 @@ -0,0 +1 @@ +{"error":"Couldn't find: null","result":"error"} \ No newline at end of file diff --git a/test.sh.downloaded2 b/test.sh.downloaded2 new file mode 100644 index 0000000..b7341ef --- /dev/null +++ b/test.sh.downloaded2 @@ -0,0 +1 @@ +{"error":"Couldn't find: autotest:test1","result":"error"} \ No newline at end of file