From 1f045515eafc83aa5214c72774bdbbc6500723f3 Mon Sep 17 00:00:00 2001 From: kamiyaa Date: Sat, 31 Aug 2024 09:56:09 -0400 Subject: [PATCH] fix crash when io operation did not successfully start --- src/run/process_event.rs | 56 ++++++++++++++++----------------- src/types/state/worker_state.rs | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/run/process_event.rs b/src/run/process_event.rs index c25ba1377..aefd94392 100644 --- a/src/run/process_event.rs +++ b/src/run/process_event.rs @@ -107,39 +107,39 @@ pub fn process_io_task_progress(app_state: &mut AppState, res: IoTaskProgressMes } pub fn process_finished_io_task(app_state: &mut AppState, res: AppResult) { - let worker_state = app_state.state.worker_state_mut(); - let observer = worker_state.remove_worker().unwrap(); - - let observer_path = observer.dest_path(); - if observer_path.exists() { - let _ = tab_ops::reload_all_tabs(app_state, observer_path); - } else { - tab_ops::remove_entry_from_all_tabs(app_state, observer_path); - } - - let observer_path = observer.src_path(); - if observer_path.exists() { - let _ = tab_ops::reload_all_tabs(app_state, observer_path); - } else { - tab_ops::remove_entry_from_all_tabs(app_state, observer_path); - } - - let progress = observer.progress.clone(); match res { - Ok(_) => { - let op = progress.kind.actioned_str(); - let processed_size = format::file_size_to_string(progress.bytes_processed); - let total_size = format::file_size_to_string(progress.total_bytes); - let msg = format!( - "successfully {} {} items ({}/{})", - op, progress.total_files, processed_size, total_size, - ); - app_state.state.message_queue_mut().push_success(msg); - } Err(err) => { let msg = format!("{err}"); app_state.state.message_queue_mut().push_error(msg); } + Ok(_) => { + let worker_state = app_state.state.worker_state_mut(); + if let Some(io_stat) = worker_state.remove_io_stat() { + let io_path = io_stat.dest_path(); + if io_path.exists() { + let _ = tab_ops::reload_all_tabs(app_state, io_path); + } else { + tab_ops::remove_entry_from_all_tabs(app_state, io_path); + } + + let io_path = io_stat.src_path(); + if io_path.exists() { + let _ = tab_ops::reload_all_tabs(app_state, io_path); + } else { + tab_ops::remove_entry_from_all_tabs(app_state, io_path); + } + + let progress = io_stat.progress; + let op = progress.kind.actioned_str(); + let processed_size = format::file_size_to_string(progress.bytes_processed); + let total_size = format::file_size_to_string(progress.total_bytes); + let msg = format!( + "successfully {} {} items ({}/{})", + op, progress.total_files, processed_size, total_size, + ); + app_state.state.message_queue_mut().push_success(msg); + } + } } app_state.state.worker_state_mut().progress = None; process_new_io_task(app_state); diff --git a/src/types/state/worker_state.rs b/src/types/state/worker_state.rs index 9dd43723c..d06b8d86c 100644 --- a/src/types/state/worker_state.rs +++ b/src/types/state/worker_state.rs @@ -70,7 +70,7 @@ impl WorkerState { Ok(()) } - pub fn remove_worker(&mut self) -> Option { + pub fn remove_io_stat(&mut self) -> Option { self.progress.take() } }