diff --git a/Cargo.lock b/Cargo.lock index 27c78cd..f2a4e2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,15 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + [[package]] name = "iana-time-zone" version = "0.1.61" @@ -146,6 +155,7 @@ name = "rr" version = "0.1.1" dependencies = [ "chrono", + "home", ] [[package]] @@ -235,6 +245,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index a654a9c..c7554fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] chrono = "0.4.38" +home = "0.5" \ No newline at end of file diff --git a/scripts/installer/install_rr_amd64.sh b/scripts/installer/install_rr_amd64.sh index 65ee9b4..d943471 100644 --- a/scripts/installer/install_rr_amd64.sh +++ b/scripts/installer/install_rr_amd64.sh @@ -1,7 +1,7 @@ #!/bin/bash # 定义下载 URL 和目标路径 -URL="https://github.com/kites262/Recoverable_Removal/releases/download/v0.1.1/rr-amd64" +URL="https://github.com/kites262/Recoverable_Removal/releases/download/v0.1.2/rr-amd64" DEST="/usr/local/bin/rr" # 下载文件 diff --git a/src/main.rs b/src/main.rs index e437329..0b0894b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::fs::{self, OpenOptions}; use std::io::Write; use std::path::PathBuf; use chrono::Local; +use home::home_dir; fn main() { // Get command line arguments, skipping the first one (program name) @@ -12,12 +13,16 @@ fn main() { std::process::exit(1); } + // Get user's home directory + let home_path = home_dir().expect("Unable to find home directory"); + let base_removed_dir = home_path.join(".rr_removed"); + if args[0] == "--restore" { // Handle restore functionality println!("Starting restore process..."); // Read last.tag file - let last_tag_path = PathBuf::from("/var/tmp/rr_removed/last.tag"); + let last_tag_path = base_removed_dir.join("last.tag"); let last_tag_contents = fs::read_to_string(&last_tag_path) .expect("Unable to read last.tag file"); @@ -35,8 +40,8 @@ fn main() { // Write back the rest of the lines to last.tag fs::write(&last_tag_path, lines.join("\n")).expect("Unable to write to last.tag file"); - // Construct base_dir as /var/tmp/rr_removed/{timestamp} - let base_dir = PathBuf::from("/var/tmp/rr_removed").join(×tamp); + // Construct base_dir as ~/.rr_removed/{timestamp} + let base_dir = base_removed_dir.join(×tamp); // Read rr_removed.restore_path.txt to get restore path let restore_path_file_path = base_dir.join("rr_removed.restore_path.txt"); @@ -102,17 +107,14 @@ fn main() { println!("Files have been successfully restored to: \n{}", restore_path.display()); } - // Optionally, remove the base_dir - // fs::remove_dir_all(&base_dir).expect("Unable to remove base directory"); - } else { // Handle delete (move to trash) functionality // Get the current date in the format YYYY-MM-DD let date = Local::now().format("%Y-%m-%d-%H-%M-%S-%f").to_string(); - // Construct the base directory path /var/tmp/rr_removed/{timestamp} - let base_dir = PathBuf::from("/var/tmp/rr_removed").join(&date); + // Construct the base directory path ~/.rr_removed/{timestamp} + let base_dir = base_removed_dir.join(&date); // Create the restore directory let restore_dir = base_dir.join("restore"); @@ -124,7 +126,7 @@ fn main() { } // Append the timestamp to last.tag - let last_tag_path = PathBuf::from("/var/tmp/rr_removed/last.tag"); + let last_tag_path = base_removed_dir.join("last.tag"); let mut last_tag_file = OpenOptions::new() .create(true) .append(true) @@ -165,8 +167,6 @@ fn main() { if let Err(e) = fs::rename(&src, &dest) { eprintln!("Error moving {} to {}: {}", src.display(), dest.display(), e); continue; - } else { - // println!("Delete '{}', files restored to '{}'", src.display(), dest.display()); } } }