From 1309ed34b4dc7c142e8829ff9c8c03c159969162 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Fri, 9 Dec 2022 15:00:00 -0600 Subject: [PATCH] Skip renaming if destination exists --- src/functions.rs | 8 ++++++-- src/main.rs | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/functions.rs b/src/functions.rs index e40616c..c6195ea 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -2,7 +2,7 @@ use inquire::{ ui::{Color, IndexPrefix, RenderConfig, Styled}, Select, }; -use std::{collections::HashMap, fs, process::exit}; +use std::{collections::HashMap, fs, path::Path, process::exit}; use tmdb::{model::*, themoviedb::*}; use torrent_name_parser::Metadata; @@ -117,7 +117,11 @@ pub fn process_file( println!("[file] '{}' -> '{}'", file_base, new_name_with_ext); // Only do the rename of --dry-run isn't passed if dry_run == false { - fs::rename(filename, new_name.as_str()).expect("Unable to rename file!"); + if Path::new(new_name.as_str()).is_file() == false { + fs::rename(filename, new_name.as_str()).expect("Unable to rename file!"); + } else { + eprintln!("Destination file already exists, skipping..."); + } } } (new_name_base, is_subtitle) diff --git a/src/main.rs b/src/main.rs index 7717880..bf5f738 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,7 +82,12 @@ fn main() { } else { println!("[directory] '{}' -> '{}'", entry_clean, movie_name); if settings["dry_run"] == false { - fs::rename(entry, movie_name).expect("Unable to rename directory!"); + if Path::new(movie_name.as_str()).is_dir() == false { + fs::rename(entry, movie_name) + .expect("Unable to rename directory!"); + } else { + eprintln!("Destination directory already exists, skipping..."); + } } } } else {