diff --git a/src/autocomplete.cpp b/src/autocomplete.cpp index 8c2c9c3..7451a2c 100644 --- a/src/autocomplete.cpp +++ b/src/autocomplete.cpp @@ -58,10 +58,11 @@ void dropshell::autocomplete(const std::vector &args) if (args.size()==5) // we have the command and the server and the service. dropshell autocomplete command server service_name { + std::string server_name = args[3]; std::string service_name = args[4]; if (cmd=="restore") { - std::set backups = dropshell::list_backups(service_name); + std::set backups = dropshell::list_backups(server_name, service_name); for (auto backup : backups) std::cout << backup << std::endl; return; diff --git a/src/services.cpp b/src/services.cpp index 09bb8eb..a9f071b 100644 --- a/src/services.cpp +++ b/src/services.cpp @@ -122,13 +122,20 @@ std::set get_used_commands(const std::string &server_name, const st return commands; } -std::set list_backups(const std::string &service_name) +std::set list_backups(const std::string &server_name, const std::string &service_name) { std::set backups; - if (service_name.empty()) + if (server_name.empty() || service_name.empty()) return backups; + // need to find the template for the service. + ServiceInfo service_info = get_service_info(server_name, service_name); + if (service_info.local_template_path.empty()) { + std::cerr << "Error: Service not found: " << service_name << std::endl; + return backups; + } + std::string backups_dir = localpath::backups_path(); if (backups_dir.empty()) return backups; @@ -136,7 +143,7 @@ std::set list_backups(const std::string &service_name) if (fs::exists(backups_dir)) { for (const auto& entry : fs::directory_iterator(backups_dir)) { if (fs::is_regular_file(entry) && entry.path().extension() == ".tgz") - if (entry.path().filename().string().find(service_name) != std::string::npos) + if (entry.path().filename().string().find(service_info.template_name) != std::string::npos) { backups.insert(entry.path().filename().string()); } diff --git a/src/services.hpp b/src/services.hpp index 86751ca..5745a10 100644 --- a/src/services.hpp +++ b/src/services.hpp @@ -20,7 +20,7 @@ namespace dropshell { std::set get_used_commands(const std::string& server_name, const std::string& service_name); // list all backups for a given service (across all servers) - std::set list_backups(const std::string& service_name); + std::set list_backups(const std::string& server_name, const std::string& service_name); bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name, bool silent=false); } // namespace dropshell