diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-05-29 12:18:55 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-05-29 12:18:55 +0800 |
commit | e68481f3524d214b76d2895a10febc3a524c3256 (patch) | |
tree | 01b2eeb2230bfe7e0f441f5de477f28d15653cc6 | |
parent | 78a68b1a9ed5d39d250c5478041e40425a198756 (diff) |
Add simple progress to indicate something is happening on long `dua` runs
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/aggregate.rs | 28 | ||||
-rw-r--r-- | src/main.rs | 9 |
3 files changed, 39 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 27406ff..7ae245f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +#### v2.12 + +* Add minimal progress for when `dua` invocations take longer than 1 second + #### v2.11.3 - re-add arm builds * dependency updates (including tui 0.15) diff --git a/src/aggregate.rs b/src/aggregate.rs index d6c41f0..8087060 100644 --- a/src/aggregate.rs +++ b/src/aggregate.rs @@ -2,13 +2,24 @@ use crate::{crossdev, InodeFilter, WalkOptions, WalkResult}; use anyhow::Result; use colored::{Color, Colorize}; use filesize::PathExt; -use std::{borrow::Cow, io, path::Path}; +use std::time::Duration; +use std::{ + borrow::Cow, + io, + path::Path, + sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }, + thread, +}; /// Aggregate the given `paths` and write information about them to `out` in a human-readable format. /// If `compute_total` is set, it will write an additional line with the total size across all given `paths`. /// If `sort_by_size_in_bytes` is set, we will sort all sizes (ascending) before outputting them. pub fn aggregate( mut out: impl io::Write, + mut err: impl io::Write + Send + 'static, walk_options: WalkOptions, compute_total: bool, sort_by_size_in_bytes: bool, @@ -24,6 +35,20 @@ pub fn aggregate( let mut aggregates = Vec::new(); let mut inodes = InodeFilter::default(); let paths: Vec<_> = paths.into_iter().collect(); + let shared_count = Arc::new(AtomicU64::new(0)); + thread::spawn({ + let shared_count = Arc::clone(&shared_count); + thread::sleep(Duration::from_secs(1)); + move || loop { + thread::sleep(Duration::from_millis(100)); + write!( + err, + "Enumerating {} entries\r", + shared_count.load(Ordering::Relaxed) + ) + .ok(); + } + }); for path in paths.into_iter() { num_roots += 1; let mut num_bytes = 0u128; @@ -31,6 +56,7 @@ pub fn aggregate( let device_id = crossdev::init(path.as_ref())?; for entry in walk_options.iter_from_path(path.as_ref()) { stats.entries_traversed += 1; + shared_count.fetch_add(1, Ordering::Relaxed); match entry { Ok(entry) => { let file_size = match entry.client_state { diff --git a/src/main.rs b/src/main.rs index d45672f..f8cdabc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,12 @@ use anyhow::Result; use clap::Clap; use dua::{ByteFormat, TraversalSorting}; -use std::{fs, io, io::Write, path::PathBuf, process}; +use std::{ + fs, io, + io::{stderr, Write}, + path::PathBuf, + process, +}; mod crossdev; #[cfg(any(feature = "tui-unix", feature = "tui-crossplatform"))] @@ -67,6 +72,7 @@ fn main() -> Result<()> { let stdout_locked = stdout.lock(); let (res, stats) = dua::aggregate( stdout_locked, + stderr(), walk_options, !no_total, !no_sort, @@ -82,6 +88,7 @@ fn main() -> Result<()> { let stdout_locked = stdout.lock(); dua::aggregate( stdout_locked, + stderr(), walk_options, true, true, |