diff --git a/src/service_versions.cpp b/src/service_versions.cpp new file mode 100644 index 0000000..7d1266a --- /dev/null +++ b/src/service_versions.cpp @@ -0,0 +1,70 @@ +#include "service_runner.hpp" +#include "utils/hash.hpp" +#include "utils/directories.hpp" +#include "utils/utils.hpp" +#include "templates.hpp" + +#include +#include +#include + +namespace fs = std::filesystem; + +namespace dropshell { + +service_versions::service_versions(const std::string & server_name, const std::string & service_name) + : m_server_name(server_name), m_service_name(service_name) +{ +} + +XXH64_hash_t service_versions::calculate_version_local_service_template() +{ + template_info tinfo; + if (!get_template_info(m_service_name, tinfo)) { + return 0; + } + return hash_directory_recursive(tinfo.local_template_path); +} + +XXH64_hash_t service_versions::calculate_version_local_config() +{ + std::string config_path = get_local_service_path(m_server_name, m_service_name); + if (config_path.empty() || !fs::exists(config_path)) { + return 0; + } + return hash_directory_recursive(config_path); +} + +void service_versions::update_stored_remote_versions() +{ + XXH64_hash_t template_hash = calculate_version_remote_service_template(); + XXH64_hash_t config_hash = calculate_version_remote_config(); + + // TODO - actually update things! +} + +XXH64_hash_t service_versions::get_version_remote_config() +{ + // TODO - actually get the version! + return 0; +} + +XXH64_hash_t service_versions::get_version_remote_service_template() +{ + // TODO - actually get the version! + return 0; +} + +XXH64_hash_t service_versions::calculate_version_remote_service_template() +{ + // TODO - actually get the version! + return 0; +} + +XXH64_hash_t service_versions::calculate_version_remote_config() +{ + // TODO - actually get the version! + return 0; +} + +} // namespace dropshell \ No newline at end of file diff --git a/src/templates.cpp b/src/templates.cpp index 0ddf03f..792c7b2 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -115,7 +115,7 @@ return; } - std::string user_templates_dir = local_config_directories[0] + "/templates"; + std::string user_templates_dir = get_primary_local_config_path() + "/templates"; std::string new_template_path = user_templates_dir + "/" + template_name; // Create the new template directory diff --git a/src/utils/directories.cpp b/src/utils/directories.cpp index 05ed728..ac6cce5 100644 --- a/src/utils/directories.cpp +++ b/src/utils/directories.cpp @@ -36,6 +36,14 @@ std::string get_local_system_templates_path() return "/opt/dropshell/templates"; } +std::string get_local_backup_path() +{ + config *cfg = get_global_config(); + if (!cfg) + return std::string(); + return cfg->get_local_backup_path(); +} + int getNumConfigDirectories() { config *cfg = get_global_config(); @@ -43,6 +51,11 @@ int getNumConfigDirectories() return local_config_directories.size(); } +std::string get_primary_local_config_path() +{ + return get_local_config_path(0); +} + std::string get_local_config_path(int index) { config *cfg = get_global_config(); @@ -55,16 +68,6 @@ std::string get_local_config_path(int index) return local_config_directories[index]; } - -std::string get_local_backup_path() -{ - config *cfg = get_global_config(); - if (!cfg) - return std::string(); - - return cfg->get_local_backup_path(); -} - std::string get_local_config_templates_path(int index) { std::string config_path = get_local_config_path(index); @@ -81,14 +84,6 @@ std::string get_local_config_servers_path(int index) return config_path + "/servers"; } -std::string get_local_config_backups_path(int index) -{ - std::string config_path = get_local_config_path(index); - if (config_path.empty()) - return std::string(); - return config_path + "/backups"; -} - std::string get_local_server_path(const std::string &server_name) { config *cfg = get_global_config(); @@ -133,6 +128,18 @@ std::string get_local_service_env_path(const std::string &server_name, const std return (fs::path(servicepath) / "service.env").string(); } +std::string get_local_service_hash_path(const std::string &server_name, const std::string &service_name) +{ + if (server_name.empty() || service_name.empty()) + return std::string(); + + std::string config_path = get_primary_local_config_path(); + if (config_path.empty()) + return std::string(); + + return (fs::path(config_path) / ".remote_versions" / server_name / (service_name + ".hash.env")).string(); +} + // ------------------------------------------------------------------------------------------ // remote paths diff --git a/src/utils/directories.hpp b/src/utils/directories.hpp index 476b636..ec172c2 100644 --- a/src/utils/directories.hpp +++ b/src/utils/directories.hpp @@ -9,7 +9,6 @@ namespace dropshell { std::string get_local_dropshell_config_parent_path(); std::string get_local_dropshell_config_file(); std::string get_local_system_templates_path(); - std::string get_local_backup_path(); @@ -28,22 +27,17 @@ namespace dropshell { // | |-- example // | |-- service.env // | |-- (other service config files) + // |-- .remote_versions + // | |-- server_name + // | |-- service_name.hash.env + std::string get_primary_local_config_path(); - // system config directories (installed from templates in this git repository) - // /opt/dropshell - // |-- templates - // | |-- template_name - // | |-- (script files) - // | |-- example - // | |-- service.env - // | |-- (other service config files) int getNumConfigDirectories(); std::string get_local_config_path(int index); std::string get_local_config_templates_path(int index); std::string get_local_config_servers_path(int index); - std::string get_local_config_backups_path(int index); std::string get_local_server_path(const std::string &server_name); std::string get_local_server_env_path(const std::string &server_name); @@ -51,6 +45,8 @@ namespace dropshell { std::string get_local_service_path(const std::string &server_name, const std::string &service_name); std::string get_local_service_env_path(const std::string &server_name, const std::string &service_name); + std::string get_local_service_hash_path(const std::string &server_name, const std::string &service_name); + // remote paths // DROPSHELL_DIR // |-- backups