diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-03-17 18:07:04 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-03-17 18:07:04 -0400 |
commit | e9ba4d33fb582f5a1ee556ba75319254d6bb51b6 (patch) | |
tree | ece7dc2c253d4a116d2f0b2e4518ef110396105e /src | |
parent | a0286692964d120ee8a6ea36fbfb2f577dc2305c (diff) |
fix cut
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/file_ops/paste_copy.rs | 17 | ||||
-rw-r--r-- | src/commands/file_ops/paste_cut.rs | 49 | ||||
-rw-r--r-- | src/commands/reload_dir.rs | 20 | ||||
-rw-r--r-- | src/main.rs | 14 | ||||
-rw-r--r-- | src/run.rs | 4 |
5 files changed, 65 insertions, 39 deletions
diff --git a/src/commands/file_ops/paste_copy.rs b/src/commands/file_ops/paste_copy.rs index b1a7368..b3234bf 100644 --- a/src/commands/file_ops/paste_copy.rs +++ b/src/commands/file_ops/paste_copy.rs @@ -49,14 +49,19 @@ pub fn paste_copy( let (tx_start, rx_start) = mpsc::channel(); let (tx, rx) = mpsc::channel(); + let handle: thread::JoinHandle<std::io::Result<u64>> = thread::spawn(move || { - let mut total = 0; - rx_start.recv(); - for path in paths { - total += recursive_copy(thread_dest.as_path(), path.as_path(), &options)?; - tx.send(total); + match rx_start.recv() { + Ok(_) => { + let mut total = 0; + for path in paths { + total += recursive_copy(thread_dest.as_path(), path.as_path(), &options)?; + tx.send(total); + } + Ok(total) + } + Err(_) => Ok(0), } - Ok(total) }); let thread = IOWorkerThread { diff --git a/src/commands/file_ops/paste_cut.rs b/src/commands/file_ops/paste_cut.rs index 2bb9adc..5b6683b 100644 --- a/src/commands/file_ops/paste_cut.rs +++ b/src/commands/file_ops/paste_cut.rs @@ -17,23 +17,29 @@ pub fn recursive_cut(dest: &Path, src: &Path, options: &Options) -> std::io::Res rename_filename_conflict(&mut dest_buf); if !src.is_dir() { let metadata = src.metadata()?; - match std::fs::rename(src, dest_buf.as_path()) { - Err(_) => { - std::fs::copy(src, dest_buf.as_path())?; - std::fs::remove_file(src)?; - } - _ => {} + if fs::rename(src, dest_buf.as_path()).is_err() { + fs::copy(src, dest_buf.as_path())?; + fs::remove_file(src)?; } Ok(metadata.len()) } else { - fs::create_dir(dest_buf.as_path())?; - let mut total = 0; - for entry in fs::read_dir(src)? { - let entry = entry?; - let entry_path = entry.path(); - total += recursive_cut(dest_buf.as_path(), entry_path.as_path(), options)?; + match fs::rename(src, dest_buf.as_path()) { + Ok(_) => { + let metadata = dest_buf.metadata()?; + Ok(metadata.len()) + } + Err(_) => { + fs::create_dir(dest_buf.as_path())?; + let mut total = 0; + for entry in fs::read_dir(src)? { + let entry = entry?; + let entry_path = entry.path(); + total += recursive_cut(dest_buf.as_path(), entry_path.as_path(), options)?; + } + fs::remove_dir(src)?; + Ok(total) + } } - Ok(total) } } @@ -57,14 +63,19 @@ pub fn paste_cut( let (tx_start, rx_start) = mpsc::channel(); let (tx, rx) = mpsc::channel(); + let handle: thread::JoinHandle<std::io::Result<u64>> = thread::spawn(move || { - let mut total = 0; - rx_start.recv(); - for path in paths { - total += recursive_cut(thread_dest.as_path(), path.as_path(), &options)?; - tx.send(total); + match rx_start.recv() { + Ok(_) => { + let mut total = 0; + for path in paths { + total += recursive_cut(thread_dest.as_path(), path.as_path(), &options)?; + tx.send(total); + } + Ok(total) + } + Err(_) => Ok(0), } - Ok(total) }); let thread = IOWorkerThread { diff --git a/src/commands/reload_dir.rs b/src/commands/reload_dir.rs index 88cfc46..2951e9f 100644 --- a/src/commands/reload_dir.rs +++ b/src/commands/reload_dir.rs @@ -1,4 +1,4 @@ -use crate::commands::{JoshutoCommand, JoshutoRunnable}; +use crate::commands::{CursorMoveStub, JoshutoCommand, JoshutoRunnable}; use crate::context::JoshutoContext; use crate::error::JoshutoResult; use crate::ui::TuiBackend; @@ -18,17 +18,14 @@ impl ReloadDirList { let curr_tab = &mut context.tabs[index]; let sort_option = &context.config_t.sort_option; - match curr_tab.curr_list_mut() { - Some(curr_list) => curr_list.reload_contents(sort_option)?, - None => {} + if let Some(curr_list) = curr_tab.curr_list_mut() { + curr_list.reload_contents(sort_option)?; } - match curr_tab.parent_list_mut() { - Some(curr_list) => curr_list.reload_contents(sort_option)?, - None => {} + if let Some(curr_list) = curr_tab.parent_list_mut() { + curr_list.reload_contents(sort_option)?; } - match curr_tab.child_list_mut() { - Some(curr_list) => curr_list.reload_contents(sort_option)?, - None => {} + if let Some(curr_list) = curr_tab.child_list_mut() { + curr_list.reload_contents(sort_option)?; } Ok(()) @@ -44,8 +41,9 @@ impl std::fmt::Display for ReloadDirList { } impl JoshutoRunnable for ReloadDirList { - fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> { + fn execute(&self, context: &mut JoshutoContext, backend: &mut TuiBackend) -> JoshutoResult<()> { Self::reload(context.curr_tab_index, context)?; + CursorMoveStub::new().execute(context, backend)?; Ok(()) } } diff --git a/src/main.rs b/src/main.rs index d11aafd..5820b1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ mod util; use lazy_static::lazy_static; use std::path::PathBuf; +use std::process; use structopt::StructOpt; use config::{ @@ -68,7 +69,13 @@ fn main() { return; } if let Some(p) = args.path { - std::env::set_current_dir(p.as_path()); + match std::env::set_current_dir(p.as_path()) { + Ok(_) => {}, + Err(e) => { + eprintln!("{}", e); + process::exit(1); + } + } } let config = JoshutoConfig::get_config(); @@ -76,6 +83,9 @@ fn main() { match run(config, keymap) { Ok(_) => {} - Err(e) => eprintln!("{}", e), + Err(e) => { + eprintln!("{}", e); + process::exit(1); + } } } @@ -58,7 +58,8 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io: handle.join(); let msg = match res { Ok(s) => { - format!("io_worker completed successfully: {} bytes processed", s) + format!("io_worker completed successfully: {:.3} KB processed", + s as f64 / 1024.0) } Err(e) => format!("io_worker was not completed: {}", e.to_string()), }; @@ -68,6 +69,7 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) -> std::io: tab.history.create_or_update(src.as_path(), options); tab.history.create_or_update(dest.as_path(), options); } + CursorMoveStub::new().execute(&mut context, &mut backend); } None => {} } |