From d80820db1553e6365cf0ce89dae6dad3fdd080af Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 18 May 2025 20:23:15 +1200 Subject: [PATCH] Back to issue from pre-refactor! --- source/src/commands/restoredata.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/src/commands/restoredata.cpp b/source/src/commands/restoredata.cpp index 096319b..6c66f10 100644 --- a/source/src/commands/restoredata.cpp +++ b/source/src/commands/restoredata.cpp @@ -90,7 +90,7 @@ namespace dropshell ASSERT(ctx.args.size() == 3, "Invalid number of arguments"); std::string server = ctx.args[0]; std::string service = ctx.args[1]; - std::string backup_file = ctx.args[2]; + std::string backup_arg = ctx.args[2]; server_env_manager server_env(server); if (!server_env.is_valid()) @@ -106,7 +106,7 @@ namespace dropshell } std::optional backup_details; - if (backup_file == "latest") + if (backup_arg == "latest") { // special case. std::vector backups = get_backup_files(server, service, service_info.template_name); // this service only (and also match template in case something changed there!). if (backups.empty()) @@ -117,15 +117,15 @@ namespace dropshell } backup_details = backups[0]; } else { - backup_details = shared_commands::cBackupFileName(backup_file); + backup_details = shared_commands::cBackupFileName(backup_arg); + if (!backup_details->is_valid()) + { + error << "Invalid backup file: " << backup_arg << std::endl; + return 1; + } } - bool backup_details_okay = backup_details.has_value() && backup_details->is_valid(); - if (!backup_details_okay) - { - error << "Invalid backup file: " << backup_file << std::endl; - return 1; - } + ASSERT(backup_details.has_value() && backup_details->is_valid(), "Invalid backup file."); std::string local_backups_dir = gConfig().get_local_backup_path(); if (local_backups_dir.empty() || !std::filesystem::exists(local_backups_dir)) @@ -133,7 +133,7 @@ namespace dropshell error << "Error: Local backups directory not found: " << local_backups_dir << std::endl; return 1; } - std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_file).string(); + std::string local_backup_file_path = (std::filesystem::path(local_backups_dir) / backup_details->get_filename()).string(); if (!std::filesystem::exists(local_backup_file_path)) { error << "Error: Backup file not found at " << local_backup_file_path << std::endl; @@ -177,7 +177,7 @@ namespace dropshell { // restore service from backup info << "3) Restoring service data from backup..." << std::endl; std::string remote_backups_dir = remotepath::backups(server); - std::string remote_backup_file_path = remote_backups_dir + "/" + backup_file; + std::string remote_backup_file_path = remote_backups_dir + "/" + backup_details->get_filename(); // Copy backup file from local to server if (!shared_commands::scp_file_to_remote(server_env, local_backup_file_path, remote_backup_file_path, false))