From 080e38456073addff982155b1f1f8820cc3dc0b0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 4 May 2025 14:10:46 +1200 Subject: [PATCH] . --- src/service_runner.cpp | 18 +++++++++--------- src/templates.cpp | 15 +++------------ src/templates.hpp | 8 ++++---- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/service_runner.cpp b/src/service_runner.cpp index 540ff3f..00dd9ee 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -42,8 +42,8 @@ bool service_runner::install() { if (!mServerEnv.is_valid()) return false; // should never hit this. // Check if template exists - template_info tinfo; - if (!get_template_info(mServiceInfo.template_name, tinfo)) + template_info tinfo = gTemplateManager().get_template_info(mServiceInfo.template_name); + if (!tinfo.is_set()) return false; // Create service directory @@ -65,9 +65,9 @@ bool service_runner::install() { // Copy template files { - std::cout << "Copying: [LOCAL] " << tinfo.local_template_path << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_template(mServer, mService) << "/" << std::endl; + std::cout << "Copying: [LOCAL] " << tinfo.local_template_path() << std::endl << std::string(8,' ')<<"[REMOTE] " << remotepath::service_template(mServer, mService) << "/" << std::endl; std::string rsync_cmd = "rsync --delete -zrpc -e 'ssh -p " + mServerEnv.get_SSH_PORT() + "' " + - quote(tinfo.local_template_path + "/") + " "+ + quote(tinfo.local_template_path().string()+"/") + " "+ mServerEnv.get_SSH_USER() + "@" + mServerEnv.get_SSH_HOST() + ":" + quote(remotepath::service_template(mServer, mService)+"/"); //std::cout << std::endl << rsync_cmd << std::endl << std::endl; @@ -195,8 +195,8 @@ bool service_runner::run_command(const std::string& command, std::vector service_runner::get_all_services_status(std std::string command = "_allservicesstatus"; std::string service_name = "dropshell-agent"; - if (!template_command_exists(service_name, command)) + if (!gTemplateManager().template_command_exists(service_name, command)) { std::cerr << "Error: " << service_name << " does not contain the " << command << " script" << std::endl; return status; @@ -604,7 +604,7 @@ bool service_runner::backup(bool silent) { const std::string command = "backup"; - if (!template_command_exists(service_info.template_name, command)) { + if (!gTemplateManager().template_command_exists(service_info.template_name, command)) { std::cout << "No backup script for " << service_info.template_name << std::endl; return true; // nothing to back up. } diff --git a/src/templates.cpp b/src/templates.cpp index a8f9ea2..c5d1935 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -37,18 +37,9 @@ return std::filesystem::exists(mLocalPath / template_name); } - std::string template_source_local::template_command_filename(const std::string& template_name, const std::string& command) { - std::vector commands = { - command, - command + ".sh" - }; - - for (const auto& cmd : commands) { - std::filesystem::path path = mLocalPath / template_name / cmd; - if (std::filesystem::exists(path)) - return cmd; - } - return ""; + bool template_source_local::template_command_exists(const std::string& template_name, const std::string& command) { + std::filesystem::path path = mLocalPath / template_name / (command+".sh"); + return std::filesystem::exists(path); } template_info template_source_local::get_template_info(const std::string& template_name) { diff --git a/src/templates.hpp b/src/templates.hpp index bd1da32..dae65c4 100644 --- a/src/templates.hpp +++ b/src/templates.hpp @@ -36,7 +36,7 @@ class template_source_interface { virtual std::set get_template_list() = 0; virtual bool has_template(const std::string& template_name) = 0; virtual template_info get_template_info(const std::string& template_name) = 0; - virtual std::string template_command_filename(const std::string& template_name,const std::string& command) = 0; + virtual bool template_command_exists(const std::string& template_name,const std::string& command) = 0; }; class template_source_registry : public template_source_interface { @@ -48,7 +48,7 @@ class template_source_registry : public template_source_interface { std::set get_template_list(); bool has_template(const std::string& template_name); template_info get_template_info(const std::string& template_name); - std::string template_command_filename(const std::string& template_name,const std::string& command); + bool template_command_exists(const std::string& template_name,const std::string& command); private: std::filesystem::path get_cache_dir(); private: @@ -63,7 +63,7 @@ class template_source_local : public template_source_interface { std::set get_template_list(); bool has_template(const std::string& template_name); template_info get_template_info(const std::string& template_name); - std::string template_command_filename(const std::string& template_name,const std::string& command); + bool template_command_exists(const std::string& template_name,const std::string& command); private: std::filesystem::path mLocalPath; }; @@ -77,7 +77,7 @@ class template_manager { bool has_template(const std::string& template_name); template_info get_template_info(const std::string& template_name); - std::string template_command_filename(const std::string& template_name,const std::string& command); + bool template_command_exists(const std::string& template_name,const std::string& command); void create_template(const std::string& template_name); bool test_template(const std::string& template_path);