mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
Refactor: Update main for progress bar
This commit is contained in:
+3
-3
@@ -32,8 +32,8 @@ pub struct WalkData<'a> {
|
||||
pub by_filecount: bool,
|
||||
pub ignore_hidden: bool,
|
||||
pub follow_links: bool,
|
||||
pub progress_config: Option<&'a Arc<PConfig>>,
|
||||
pub progress_data: Option<&'a Arc<PAtomicInfo>>,
|
||||
pub progress_config: Option<Arc<PConfig>>,
|
||||
pub progress_data: Option<Arc<PAtomicInfo>>,
|
||||
}
|
||||
|
||||
pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: WalkData) -> (Vec<Node>, bool) {
|
||||
@@ -44,7 +44,7 @@ pub fn walk_it(dirs: HashSet<PathBuf>, walk_data: WalkData) -> (Vec<Node>, bool)
|
||||
.into_iter()
|
||||
.filter_map(|d| {
|
||||
let node = walk(d, &permissions_flag, &walk_data, 0)?;
|
||||
if let Some(data) = walk_data.progress_data {
|
||||
if let Some(data) = &walk_data.progress_data {
|
||||
data.state.set(progress::Operation::PREPARING);
|
||||
}
|
||||
clean_inodes(node, &mut inodes, walk_data.use_apparent_size)
|
||||
|
||||
+13
-14
@@ -18,6 +18,7 @@ use progress::PIndicator;
|
||||
use std::collections::HashSet;
|
||||
use std::io::BufRead;
|
||||
use std::process;
|
||||
use std::sync::Arc;
|
||||
use sysinfo::{System, SystemExt};
|
||||
|
||||
use self::display::draw_it;
|
||||
@@ -174,23 +175,21 @@ fn main() {
|
||||
|
||||
let disable_progress = config.get_disable_progress(&options);
|
||||
|
||||
let info_opt = if disable_progress {
|
||||
let info_indicator = if disable_progress {
|
||||
None
|
||||
} else {
|
||||
let conf = PConfig {
|
||||
file_count_only: by_filecount,
|
||||
use_iso: config.get_iso(&options),
|
||||
ignore_hidden,
|
||||
file_count_only: by_filecount, // recommend rm this
|
||||
use_iso: iso,
|
||||
ignore_hidden, // can we rm this?
|
||||
};
|
||||
let info = PIndicator::spawn(conf);
|
||||
|
||||
Some(info)
|
||||
Some(PIndicator::spawn(conf))
|
||||
};
|
||||
|
||||
let (info_conf, info_data) = if let Some(ref info) = info_opt {
|
||||
(Some(&info.config), Some(&info.data))
|
||||
} else {
|
||||
(None, None)
|
||||
// Must be a cleaner way to do this
|
||||
let (tmp_config, tmp_data) = match &info_indicator {
|
||||
Some(i) => (Some(Arc::clone(&i.config)), Some(Arc::clone(&i.data))),
|
||||
None => (None, None),
|
||||
};
|
||||
|
||||
let walk_data = WalkData {
|
||||
@@ -202,8 +201,8 @@ fn main() {
|
||||
by_filecount,
|
||||
ignore_hidden,
|
||||
follow_links,
|
||||
progress_config: info_conf,
|
||||
progress_data: info_data,
|
||||
progress_config: tmp_config,
|
||||
progress_data: tmp_data,
|
||||
};
|
||||
|
||||
let _rayon = init_rayon();
|
||||
@@ -225,7 +224,7 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(info) = info_opt {
|
||||
if let Some(info) = info_indicator {
|
||||
info.stop();
|
||||
}
|
||||
|
||||
|
||||
+1
-21
@@ -84,8 +84,6 @@ pub mod Operation {
|
||||
#[derive(Default)]
|
||||
pub struct PAtomicInfo {
|
||||
pub file_number: AtomicU64Wrapper,
|
||||
pub files_skipped: AtomicU64Wrapper,
|
||||
pub directories_skipped: AtomicU64Wrapper,
|
||||
pub total_file_size: TotalSize,
|
||||
pub state: AtomicU8Wrapper,
|
||||
pub current_path: ThreadStringWrapper,
|
||||
@@ -229,25 +227,7 @@ impl PIndicator {
|
||||
};
|
||||
|
||||
let main_props_str = main_props.join(PROPS_SEPARATOR);
|
||||
let base = format!("{} - {}", base, main_props_str);
|
||||
|
||||
let ds = data2.directories_skipped.get();
|
||||
let fs = data2.files_skipped.get();
|
||||
|
||||
if ds + fs != 0 {
|
||||
let mut strs = Vec::new();
|
||||
if fs != 0 {
|
||||
strs.push(format_property!(fs, "file", "files"))
|
||||
}
|
||||
|
||||
if ds != 0 {
|
||||
strs.push(format_property!(ds, "directory", "directories"))
|
||||
}
|
||||
|
||||
format!("{} ({} skipped)", base, strs.join(", "))
|
||||
} else {
|
||||
base
|
||||
}
|
||||
format!("{} - {}", base, main_props_str)
|
||||
}
|
||||
Operation::PREPARING => {
|
||||
format_base!("Preparing")
|
||||
|
||||
Reference in New Issue
Block a user