mirror of
https://github.com/bootandy/dust.git
synced 2025-12-12 07:40:40 -08:00
feat: Abort immedietly when ^C is received. (#478)
Previously, we attempted to perform a clean shutdown, which could take a significant period of time on slow filesystems. This commit changes the shutdown logic to abort immedietly when ^C is received by the program.
This commit is contained in:
@@ -206,10 +206,6 @@ fn walk(dir: PathBuf, walk_data: &WalkData, depth: usize) -> Option<Node> {
|
||||
let prog_data = &walk_data.progress_data;
|
||||
let errors = &walk_data.errors;
|
||||
|
||||
if errors.lock().unwrap().abort {
|
||||
return None;
|
||||
}
|
||||
|
||||
let children = if dir.is_dir() {
|
||||
let read_dir = fs::read_dir(&dir);
|
||||
match read_dir {
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -26,8 +26,6 @@ use std::panic;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
use sysinfo::{System, SystemExt};
|
||||
use utils::canonicalize_absolute_path;
|
||||
|
||||
@@ -119,20 +117,13 @@ fn main() {
|
||||
let errors = RuntimeErrors::default();
|
||||
let error_listen_for_ctrlc = Arc::new(Mutex::new(errors));
|
||||
let errors_for_rayon = error_listen_for_ctrlc.clone();
|
||||
let errors_final = error_listen_for_ctrlc.clone();
|
||||
let is_in_listing = Arc::new(AtomicBool::new(false));
|
||||
let cloned_is_in_listing = Arc::clone(&is_in_listing);
|
||||
|
||||
ctrlc::set_handler(move || {
|
||||
error_listen_for_ctrlc.lock().unwrap().abort = true;
|
||||
println!("\nAborting");
|
||||
if cloned_is_in_listing.load(Ordering::Relaxed) {
|
||||
process::exit(1);
|
||||
}
|
||||
process::exit(1);
|
||||
})
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
|
||||
is_in_listing.store(true, Ordering::Relaxed);
|
||||
let target_dirs = match config.get_files_from(&options) {
|
||||
Some(path) => {
|
||||
if path == "-" {
|
||||
@@ -162,7 +153,6 @@ fn main() {
|
||||
None => vec![".".to_owned()],
|
||||
},
|
||||
};
|
||||
is_in_listing.store(false, Ordering::Relaxed);
|
||||
|
||||
let summarize_file_types = options.get_flag("types");
|
||||
|
||||
@@ -304,10 +294,6 @@ fn main() {
|
||||
// Must have stopped indicator before we print to stderr
|
||||
indicator.stop();
|
||||
|
||||
if errors_final.lock().unwrap().abort {
|
||||
return;
|
||||
}
|
||||
|
||||
let final_errors = walk_data.errors.lock().unwrap();
|
||||
if !final_errors.file_not_found.is_empty() {
|
||||
let err = final_errors
|
||||
|
||||
@@ -79,7 +79,6 @@ pub struct RuntimeErrors {
|
||||
pub file_not_found: HashSet<String>,
|
||||
pub unknown_error: HashSet<String>,
|
||||
pub interrupted_error: i32,
|
||||
pub abort: bool,
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user