fixed formatting

This commit is contained in:
glitchySid
2025-12-29 21:54:11 +05:30
parent 79cfae74ea
commit a7668a6f0f
3 changed files with 24 additions and 23 deletions

View File

@@ -73,7 +73,11 @@ fn move_file_cross_platform(source: &Path, target: &Path) -> io::Result<()> {
} }
} }
pub fn execute_move(base_path: &Path, plan: OrganizationPlan, mut undo_log: Option<&mut crate::undo::UndoLog>) { pub fn execute_move(
base_path: &Path,
plan: OrganizationPlan,
mut undo_log: Option<&mut crate::undo::UndoLog>,
) {
println!("\n{}", "--- EXECUTION PLAN ---".bold().underline()); println!("\n{}", "--- EXECUTION PLAN ---".bold().underline());
if plan.files.is_empty() { if plan.files.is_empty() {
@@ -140,7 +144,7 @@ pub fn execute_move(base_path: &Path, plan: OrganizationPlan, mut undo_log: Opti
if let Ok(metadata) = fs::metadata(&source) { if let Ok(metadata) = fs::metadata(&source) {
if metadata.is_file() { if metadata.is_file() {
match move_file_cross_platform(&source, &target) { match move_file_cross_platform(&source, &target) {
Ok(_) => { Ok(_) => {
if item.sub_category.is_empty() { if item.sub_category.is_empty() {
println!("Moved: {} -> {}/", item.filename, item.category.green()); println!("Moved: {} -> {}/", item.filename, item.category.green());
@@ -197,7 +201,8 @@ pub fn undo_moves(
undo_log: &mut crate::undo::UndoLog, undo_log: &mut crate::undo::UndoLog,
dry_run: bool, dry_run: bool,
) -> Result<(usize, usize, usize), Box<dyn std::error::Error>> { ) -> Result<(usize, usize, usize), Box<dyn std::error::Error>> {
let completed_moves: Vec<_> = undo_log.get_completed_moves() let completed_moves: Vec<_> = undo_log
.get_completed_moves()
.into_iter() .into_iter()
.cloned() .cloned()
.collect(); .collect();
@@ -208,7 +213,11 @@ pub fn undo_moves(
} }
println!("\n{}", "--- UNDO PREVIEW ---".bold().underline()); println!("\n{}", "--- UNDO PREVIEW ---".bold().underline());
println!("{} will restore {} files:", "INFO:".cyan(), completed_moves.len()); println!(
"{} will restore {} files:",
"INFO:".cyan(),
completed_moves.len()
);
for record in &completed_moves { for record in &completed_moves {
if let Ok(rel_dest) = record.destination_path.strip_prefix(base_path) { if let Ok(rel_dest) = record.destination_path.strip_prefix(base_path) {
@@ -326,11 +335,7 @@ fn cleanup_empty_directories(
&& entries.next().is_none() && entries.next().is_none()
&& fs::remove_dir(&full_path).is_ok() && fs::remove_dir(&full_path).is_ok()
{ {
println!( println!("{} Removed empty directory: {}", "INFO:".cyan(), dir_path);
"{} Removed empty directory: {}",
"INFO:".cyan(),
dir_path
);
} }
} }

View File

@@ -48,10 +48,7 @@ impl UndoLog {
match fs::read_to_string(undo_log_path) { match fs::read_to_string(undo_log_path) {
Ok(content) => match serde_json::from_str::<UndoLog>(&content) { Ok(content) => match serde_json::from_str::<UndoLog>(&content) {
Ok(log) => { Ok(log) => {
println!( println!("Loaded undo log with {} entries", log.get_completed_count());
"Loaded undo log with {} entries",
log.get_completed_count()
);
log log
} }
Err(_) => { Err(_) => {
@@ -162,10 +159,7 @@ impl UndoLog {
let removed_count = initial_count - self.entries.len(); let removed_count = initial_count - self.entries.len();
if removed_count > 0 { if removed_count > 0 {
println!( println!("Cleaned up {} old undo log entries", removed_count);
"Cleaned up {} old undo log entries",
removed_count
);
} }
if self.entries.len() > self.max_entries { if self.entries.len() > self.max_entries {
@@ -211,10 +205,11 @@ impl UndoLog {
for entry in &self.entries { for entry in &self.entries {
if entry.status == MoveStatus::Completed if entry.status == MoveStatus::Completed
&& let Ok(rel_path) = entry.destination_path.strip_prefix(base_path) && let Ok(rel_path) = entry.destination_path.strip_prefix(base_path)
&& let Some(parent) = rel_path.parent() { && let Some(parent) = rel_path.parent()
let dir_path = parent.to_string_lossy().into_owned(); {
*usage.entry(dir_path).or_insert(0) += 1; let dir_path = parent.to_string_lossy().into_owned();
} *usage.entry(dir_path).or_insert(0) += 1;
}
} }
usage usage

View File

@@ -1,6 +1,6 @@
use super::*; use super::*;
use tempfile::TempDir;
use std::fs; use std::fs;
use tempfile::TempDir;
#[test] #[test]
fn test_undo_log_creation() { fn test_undo_log_creation() {
@@ -77,7 +77,8 @@ fn test_cleanup_old_entries() {
let old_timestamp = SystemTime::now() let old_timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.unwrap() .unwrap()
.as_secs() - (10 * 24 * 60 * 60); .as_secs()
- (10 * 24 * 60 * 60);
let source = PathBuf::from("/test/source.txt"); let source = PathBuf::from("/test/source.txt");
let dest = PathBuf::from("/test/dest/source.txt"); let dest = PathBuf::from("/test/dest/source.txt");