From b4b237c1b7fef97ffe6b16e546c26c26bb61326b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 5 May 2025 23:09:38 +1200 Subject: [PATCH] Use docker to root remove the local directory. --- src/main.cpp | 2 +- src/service_runner.cpp | 30 ++++++++++++++++++++++++------ src/utils/directories.cpp | 11 +++++++++-- src/utils/directories.hpp | 5 +++-- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 03c53f3..9281984 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -217,7 +217,7 @@ int main(int argc, char* argv[]) { // handle running a command. std::set commands; get_all_used_commands(commands); - commands.merge(std::set{"ssh","edit","_allservicesstatus"}); // handled by service_runner, but not in template_shell_commands. + commands.merge(std::set{"ssh","edit","_allservicesstatus","fullnuke"}); // handled by service_runner, but not in template_shell_commands. if (commands.count(cmd)) { std::set safe_commands = {"nuke", "fullnuke"}; diff --git a/src/service_runner.cpp b/src/service_runner.cpp index e8b322f..1acabc2 100644 --- a/src/service_runner.cpp +++ b/src/service_runner.cpp @@ -156,10 +156,22 @@ bool service_runner::nuke() else { // try uninstalling. - mServerEnv.run_remote_template_command(mService, "uninstall", {}); - mServerEnv.run_remote_template_command(mService, "nuke", {}); + if (gTemplateManager().template_command_exists(mServiceInfo.template_name, "uninstall")) + if (!mServerEnv.run_remote_template_command(mService, "uninstall", {})) + std::cerr << "Warning: Uninstall script failed, but continuing with directory removal" << std::endl; - std::string rm_cmd = "rm -rf " + quote(remotepath::service(mServer, mService)); + // try nuke script. + if (gTemplateManager().template_command_exists(mServiceInfo.template_name, "nuke")) + if (!mServerEnv.run_remote_template_command(mService, "nuke", {})) + std::cerr << "Warning: Nuke script failed, but continuing with directory removal" << std::endl; + + // try rm -rf. + std::string remotedir = remotepath::service(mServer, mService); + std::string remoteparentdir = get_parent(remotedir); + std::string remotechilddir = get_child(remotedir); + + std::string cmd = quote("rm -rf /parent/"+remotechilddir); + std::string rm_cmd = "docker run --rm -v "+quote(remoteparentdir)+":/parent debian bash -c "+cmd; if (!mServerEnv.execute_ssh_command(rm_cmd)) { std::cerr << "Failed to remove service directory" << std::endl; return false; @@ -168,7 +180,6 @@ bool service_runner::nuke() std::cout << "Service " << mService << " successfully nuked from " << mServer << std::endl; - std::cout << "There's nothing left on the remote server." << std::endl; std::cout << "You can remove the local files with:" << std::endl; std::cout << " rm -rf " << localpath::service(mServer,mService) << std::endl; @@ -178,9 +189,13 @@ bool service_runner::nuke() bool service_runner::fullnuke() { - if (!mServerEnv.is_valid()) return false; // should never hit this. + if (!nuke()) + { + std::cerr << "Warning: Nuke script failed, aborting fullnuke!" << std::endl; + return false; + } - std::string local_service_path = localpath::service(mServer,mService); + std::string local_service_path = mServiceInfo.local_service_path; if (local_service_path.empty() || !fs::exists(local_service_path)) { std::cerr << "Error: Service directory not found: " << local_service_path << std::endl; return false; @@ -216,6 +231,9 @@ bool service_runner::run_command(const std::string& command, std::vector +#include namespace dropshell { @@ -89,8 +90,8 @@ namespace dropshell { //------------------------------------------------------------------------------------------------ // utility functions - std::string get_parent(const std::string &path); - + std::string get_parent(const std::filesystem::path path); + std::string get_child(const std::filesystem::path path); } // namespace dropshell