This commit is contained in:
Your Name
2025-04-30 19:16:49 +12:00
parent 10050f0c27
commit 47d64a1a0d
9 changed files with 58 additions and 52 deletions

View File

@@ -11,33 +11,32 @@ namespace dropshell {
namespace localfile {
std::string dropshell_env() {
// Try ~/.config/dropshell/dropshell.env
const char* home = std::getenv("HOME");
if (home) {
fs::path user_path = fs::path(home) / ".config" / "dropshell" / "dropshell.env";
return user_path.string();
}
std::cerr << "Warning: Couldn't determine user directory" << std::endl;
return std::string();
// Try ~/.config/dropshell/dropshell.env
const char* home = std::getenv("HOME");
if (home) {
fs::path user_path = fs::path(home) / ".config" / "dropshell" / "dropshell.env";
return user_path.string();
}
std::cerr << "Warning: Couldn't determine user directory" << std::endl;
return std::string();
}
std::string server_env(const std::string &server_name) {
if (server_name.empty())
return std::string();
std::string serverpath = localpath::server(server_name);
if (serverpath.empty())
return std::string();
return (fs::path(serverpath) / "server.env").string();
return (serverpath.empty() ? "" : (fs::path(serverpath) / "server.env").string());
}
std::string service_env(const std::string &server_name, const std::string &service_name) {
if (server_name.empty() || service_name.empty())
return std::string();
std::string servicepath = localpath::service(server_name, service_name);
if (servicepath.empty())
return std::string();
return (fs::path(servicepath) / "service.env").string();
return (servicepath.empty() ? "" : (fs::path(servicepath) / "service.env").string());
}
std::string template_info_env(const std::string &server_name, const std::string &service_name)
{
std::string servicepath = localpath::service(server_name, service_name);
return (servicepath.empty() ? "" : (fs::path(servicepath) / ".template_info.env").string());
}
std::string service_hash(const std::string &server_name, const std::string &service_name) {
@@ -80,6 +79,7 @@ namespace localpath {
}
std::string server(const std::string &server_name) {
if (server_name.empty()) return "";
for (auto &dir : gConfig().get_local_config_directories())
if (fs::exists(dir + "/servers/" + server_name))
return dir + "/servers/" + server_name;
@@ -88,7 +88,7 @@ namespace localpath {
std::string service(const std::string &server_name, const std::string &service_name) {
std::string serverpath = localpath::server(server_name);
return (serverpath.empty() ? "" : (serverpath+"/"+service_name));
return (serverpath.empty() || service_name.empty() ? "" : (serverpath+"/"+service_name));
}
} // namespace localpath

View File

@@ -16,12 +16,15 @@ namespace dropshell {
// | |-- services
// | |-- service_name
// | |-- service.env
// | |-- .template_info.env
// | |-- (other config files for specific server&service)
// |-- templates
// | |-- template_name
// | |-- (script files)
// | |-- _default.env
// | |-- example
// | |-- service.env
// | |-- .template_info.env
// | |-- (other service config files)
// |-- .remote_versions
// | |-- server_name
@@ -31,6 +34,7 @@ namespace dropshell {
std::string dropshell_env();
std::string server_env(const std::string &server_name);
std::string service_env(const std::string &server_name, const std::string &service_name);
std::string template_info_env(const std::string &server_name, const std::string &service_name);
std::string service_hash(const std::string &server_name, const std::string &service_name);
} // namespace localfile