From dbbb0af459e32779d78a4688439da9050655c2ab Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 23 Apr 2025 22:16:56 +1200 Subject: [PATCH] Not working yet. --- src/server_env.cpp | 6 ++++++ src/services.cpp | 7 ++++--- src/utils/directories.cpp | 30 ++++++++++++++++++++++++------ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/server_env.cpp b/src/server_env.cpp index cd100f7..15025e7 100644 --- a/src/server_env.cpp +++ b/src/server_env.cpp @@ -12,6 +12,12 @@ bool server_env::is_valid() const { } server_env::server_env(const std::string& server_name) : mValid(false) { + if (server_name.empty()) + { + std::cerr << "Warning: Server name is empty, passed to server_env constructor." << std::endl; + return; + } + // Construct the full path to server.env std::string env_path = get_local_server_env_path(server_name); diff --git a/src/services.cpp b/src/services.cpp index 68294dd..162e27d 100644 --- a/src/services.cpp +++ b/src/services.cpp @@ -38,10 +38,8 @@ std::vector get_server_services_info(const std::string& server_name ServiceInfo get_service_info(const std::string &server_name, const std::string &service_name) { std::string service_dir = get_local_service_path(server_name, service_name); - if (service_dir.empty()) { - std::cerr << "Error: Service directory not found: " << service_dir << std::endl; + if (service_dir.empty()) return ServiceInfo(); - } ServiceInfo service; std::string local_service_env_path = get_local_service_env_path(server_name, service_name); @@ -74,6 +72,9 @@ std::set get_used_commands(const std::string &server_name, const st { std::set commands; + if (server_name.empty() || service_name.empty()) + return commands; + ServiceInfo service = get_service_info(server_name, service_name); if (service.template_path.empty()) { std::cerr << "Error: Service not found: " << service_name << std::endl; diff --git a/src/utils/directories.cpp b/src/utils/directories.cpp index dc97562..ffab664 100644 --- a/src/utils/directories.cpp +++ b/src/utils/directories.cpp @@ -41,32 +41,31 @@ std::string get_local_config_path() std::string get_local_config_templates_path() { std::string config_path = get_local_config_path(); - if (config_path.empty()) { + if (config_path.empty()) return std::string(); - } return config_path + "/templates"; } std::string get_local_config_servers_path() { std::string config_path = get_local_config_path(); - if (config_path.empty()) { + if (config_path.empty()) return std::string(); - } return config_path + "/servers"; } std::string get_local_config_backups_path() { std::string config_path = get_local_config_path(); - if (config_path.empty()) { + if (config_path.empty()) return std::string(); - } return config_path + "/backups"; } std::string get_local_server_path(const std::string &server_name) { + if (server_name.empty()) + return std::string(); std::string config_path = get_local_config_path(); if (config_path.empty()) return std::string(); @@ -75,6 +74,8 @@ std::string get_local_server_path(const std::string &server_name) std::string get_local_server_env_path(const std::string &server_name) { + if (server_name.empty()) + return std::string(); std::string serverpath = get_local_server_path(server_name); if (serverpath.empty()) return std::string(); @@ -83,6 +84,9 @@ std::string get_local_server_env_path(const std::string &server_name) std::string get_local_service_path(const std::string &server_name, const std::string &service_name) { + if (server_name.empty() || service_name.empty()) + return std::string(); + std::string serverpath = get_local_server_path(server_name); if (serverpath.empty()) return std::string(); @@ -91,6 +95,8 @@ std::string get_local_service_path(const std::string &server_name, const std::st std::string get_local_service_env_path(const std::string &server_name, const std::string &service_name) { + if (server_name.empty() || service_name.empty()) + return std::string(); std::string servicepath = get_local_service_path(server_name, service_name); if (servicepath.empty()) return std::string(); @@ -111,6 +117,8 @@ std::string get_local_service_env_path(const std::string &server_name, const std std::string get_remote_DROPSHELL_path(const std::string &server_name) { + if (server_name.empty()) + return std::string(); server_env env(server_name); if (!env.is_valid()) return std::string(); @@ -119,6 +127,8 @@ std::string get_local_service_env_path(const std::string &server_name, const std std::string get_remote_service_path(const std::string &server_name, const std::string &service_name) { + if (server_name.empty() || service_name.empty()) + return std::string(); std::string dropshell_path = get_remote_DROPSHELL_path(server_name); if (dropshell_path.empty()) return std::string(); @@ -127,6 +137,8 @@ std::string get_local_service_env_path(const std::string &server_name, const std std::string get_remote_service_config_path(const std::string &server_name, const std::string &service_name) { + if (server_name.empty() || service_name.empty()) + return std::string(); std::string service_path = get_remote_service_path(server_name, service_name); if (service_path.empty()) return std::string(); @@ -135,6 +147,8 @@ std::string get_local_service_env_path(const std::string &server_name, const std std::string get_remote_service_template_path(const std::string &server_name, const std::string &service_name) { + if (server_name.empty() || service_name.empty()) + return std::string(); std::string service_path = get_remote_service_path(server_name, service_name); if (service_path.empty()) return std::string(); @@ -143,6 +157,8 @@ std::string get_local_service_env_path(const std::string &server_name, const std std::string get_remote_service_backups_path(const std::string &server_name, const std::string &service_name) { + if (server_name.empty() || service_name.empty()) + return std::string(); std::string service_path = get_remote_service_path(server_name, service_name); if (service_path.empty()) return std::string(); @@ -151,6 +167,8 @@ std::string get_local_service_env_path(const std::string &server_name, const std std::string get_remote_service_env_file(const std::string &server_name, const std::string &service_name) { + if (server_name.empty() || service_name.empty()) + return std::string(); std::string service_path = get_remote_service_config_path(server_name, service_name); if (service_path.empty()) return std::string();