diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-12 13:29:20 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-01-12 13:29:20 -0500 |
commit | 3a482adec669fbbd901ba052ec53251ce56506b5 (patch) | |
tree | 152c87077b652c21effbf9a14635143e59d3de8f | |
parent | 1466ac5031c43174abf1ff73e0b940fefdd8033f (diff) |
fix when cutting files, overwrite occurs
-rw-r--r-- | src/joshuto/command/file_operation.rs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/joshuto/command/file_operation.rs b/src/joshuto/command/file_operation.rs index a67547c..d6b3ef8 100644 --- a/src/joshuto/command/file_operation.rs +++ b/src/joshuto/command/file_operation.rs @@ -142,7 +142,12 @@ impl PasteFiles { }; for path in (*paths).iter() { - let file_name = path.file_name().unwrap().to_str().unwrap(); + let mut file_name = path.file_name().unwrap().to_os_string(); + + while path::Path::new(&file_name).exists() { + file_name.push("_0"); + } + destination.push(file_name); if options.skip_exist && destination.exists() { continue; @@ -193,7 +198,7 @@ impl PasteFiles { let options = self.options.clone(); let child = thread::spawn(move || { - let mut files = selected_files.lock().unwrap(); + let files = selected_files.lock().unwrap(); let handle = |process_info: fs_extra::TransitProcess| { let progress_info = ProgressInfo { @@ -208,7 +213,6 @@ impl PasteFiles { Ok(_) => {}, Err(_) => {}, } - files.clear(); 0 }); @@ -363,15 +367,20 @@ impl RenameFile { if let Some(s) = user_input { let mut new_path = path.parent().unwrap().to_path_buf(); + new_path.push(s); - match fs::rename(&path, &new_path) { - Ok(_) => { - context.reload_dirlists(); - ui::refresh(&context); - }, - Err(e) => { - ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); - }, + if !new_path.exists() { + match fs::rename(&path, &new_path) { + Ok(_) => { + context.reload_dirlists(); + ui::refresh(&context); + }, + Err(e) => { + ui::wprint_err(&context.views.bot_win, e.to_string().as_str()); + }, + } + } else { + ui::wprint_err(&context.views.bot_win, "Error: File with name exists"); } } |