This commit is contained in:
Your Name
2025-05-03 19:56:20 +12:00
parent aafcc4cafe
commit 6c03512637
6 changed files with 32 additions and 39 deletions

View File

@@ -8,34 +8,20 @@ namespace simple_object_storage {
int main(int argc, char* argv[]) {
std::filesystem::path config_path = "/data/sos_config.json";
if (!std::filesystem::exists(config_path))
config_path = std::filesystem::path(std::getenv("HOME")) / ".config/simple_object_storage/config.json";
if (!std::filesystem::exists(config_path))
std::filesystem::create_directories(config_path.parent_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 config_path;
if (std::filesystem::exists(system_config_path)) config_path = system_config_path;
else if (std::filesystem::exists(user_config_path)) config_path = user_config_path;
else {
std::cout << "No config file found. Checked " << system_config_path << " and " << user_config_path << std::endl;
return 1;
}
ServerConfig config;
if (!simple_object_storage::load_config(config_path, config)) {
// output default config using heredoc to config_path
std::ofstream config_file(config_path);
config_file << R"END(
{
"write_tokens": [
"fizzle1",
"fizzle2",
"fizzle3"
],
"object_store_path": "/home/j/.simple_object_storage/",
"host": "0.0.0.0",
"port": 8123
}
)END";
config_file.close();
}
if (!simple_object_storage::load_config(config_path, config)) {
std::cerr << "Failed to load configuration at "<<config_path << std::endl;
std::cout << "Config file at " << config_path << " is not valid." << std::endl;
return 1;
}