From 0a1beeb3b7c8952d399c32b8863fa3076eaf109f Mon Sep 17 00:00:00 2001 From: Eduard Tolosa Date: Mon, 5 Feb 2024 03:27:51 -0500 Subject: [PATCH] Add better informational messages --- src/controller.rs | 9 ++++++--- src/main.rs | 8 +++++--- src/operations.rs | 9 ++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index 2809e91..6a598e6 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -49,14 +49,17 @@ pub fn manage_restoring(args: &mut Args, extra_args: &mut ExtraArgs) -> Result<( args.dest_dir = snapshot_data.source; } } - println!("Restoring the snapshot with ID {}", args.snapshot_id); - println!("Name of the snapshot: {}", extra_args.snapshot_name); - println!("Restoring snapshot to: {}", args.dest_dir); + println!( + "Restoring snapshot {} to {}", + extra_args.snapshot_name, args.dest_dir + ); if !extra_args.snapshot_name.is_empty() && operations::restore_snapshot(args, &extra_args.snapshot_name) { println!("The snapshot was successfully restored"); + } else { + eprintln!("Error while restoring the snapshot"); } Ok(()) diff --git a/src/main.rs b/src/main.rs index f4978e2..9ad841d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,9 +21,11 @@ fn try_run() -> Result<()> { database_connection: arguments.database_connection(), }; - arguments.init(&extra_args)?; - if arguments.create_snapshot { + arguments.check_for_source_and_dest_dir(); + + arguments.init(&extra_args)?; + // It's required to have a trailing slash for the source and destination directories. // Otherwise, when we retrieve the snapshot data from the database, we won't be able to // restore/delete the snapshot because the source/destination paths won't match. @@ -34,7 +36,7 @@ fn try_run() -> Result<()> { arguments.dest_dir += "/"; } - // Now we need to make sure that the paths for source and destination are full paths. + // We need to make sure that the paths for source and destination are full paths. // If they are not, we will use the current working directory to build the full path. if !Path::new(&arguments.source_dir).is_absolute() { arguments.source_dir = std::env::current_dir()? diff --git a/src/operations.rs b/src/operations.rs index f4d03ee..7477dcf 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -37,14 +37,9 @@ pub fn del_snapshot(snapshot_name: &str) -> bool { } pub fn restore_snapshot(args: &Args, snapshot_name: &str) -> bool { - (!Path::new(&args.source_dir).exists() - || Command::new("btrfs") - .args(["subvolume", "delete", &args.source_dir]) - .status() - .expect("Error deleting the subvolume.") - .success()) + !Path::new(&args.dest_dir).exists() && Command::new("btrfs") - .args(["subvolume", "snapshot", &snapshot_name, &args.source_dir]) + .args(["subvolume", "snapshot", &snapshot_name, &args.dest_dir]) .status() .expect("Error restoring the snapshot.") .success()