diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-02-22 10:54:50 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2020-02-22 10:54:50 +0800 |
commit | 4db48ce218f12e11bbf6727fab6fb58c142b1a33 (patch) | |
tree | cd5a1f0210c31d55ef1ab77682e2dba9ebaef62f | |
parent | 249539045e4dfb813723dff342c52a1ca92184ce (diff) | |
parent | d86e1e0f66ac8bd031233a6a54e2a1694acf1142 (diff) |
Merge branch 'Freaky-apparent-size'
-rw-r--r-- | Cargo.lock | 10 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/aggregate.rs | 12 | ||||
-rw-r--r-- | src/common.rs | 1 | ||||
-rw-r--r-- | src/interactive/app_test/utils.rs | 1 | ||||
-rw-r--r-- | src/main.rs | 1 | ||||
-rw-r--r-- | src/options.rs | 4 | ||||
-rw-r--r-- | src/traverse.rs | 13 |
8 files changed, 41 insertions, 2 deletions
@@ -191,6 +191,7 @@ dependencies = [ "byte-unit", "failure", "failure-tools", + "filesize", "itertools", "jwalk", "log", @@ -243,6 +244,15 @@ dependencies = [ ] [[package]] +name = "filesize" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a941e39ae509cebcd46c6734c20553a9a209b92cea5fc54618fe778fea61701" +dependencies = [ + "winapi", +] + +[[package]] name = "fixedbitset" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -25,6 +25,7 @@ log = "0.4.6" tui-react = { path = "./tui-react", version = "0.2" } num_cpus = "1.10.0" unicode-segmentation = "1.3.0" +filesize = "0.1.0" [[bin]] name="dua" diff --git a/src/aggregate.rs b/src/aggregate.rs index ff0e73b..63fed08 100644 --- a/src/aggregate.rs +++ b/src/aggregate.rs @@ -29,7 +29,17 @@ pub fn aggregate( match entry { Ok(entry) => { let file_size = match entry.metadata { - Some(Ok(ref m)) if !m.is_dir() => m.len(), + Some(Ok(ref m)) if !m.is_dir() => { + if options.apparent_size { + m.len() + } else { + filesize::file_real_size_fast(&entry.path(), m) + .unwrap_or_else(|_| { + num_errors += 1; + 0 + }) + } + }, Some(Ok(_)) => 0, Some(Err(_)) => { num_errors += 1; diff --git a/src/common.rs b/src/common.rs index 45f944d..60d0ee3 100644 --- a/src/common.rs +++ b/src/common.rs @@ -152,6 +152,7 @@ pub struct WalkOptions { /// for more information. pub threads: usize, pub byte_format: ByteFormat, + pub apparent_size: bool, pub color: Color, pub sorting: TraversalSorting, } diff --git a/src/interactive/app_test/utils.rs b/src/interactive/app_test/utils.rs index 7488143..f421665 100644 --- a/src/interactive/app_test/utils.rs +++ b/src/interactive/app_test/utils.rs @@ -164,6 +164,7 @@ pub fn initialized_app_and_terminal_with_closure<P: AsRef<Path>>( WalkOptions { threads: 1, byte_format: ByteFormat::Metric, + apparent_size: true, color: Color::None, sorting: TraversalSorting::AlphabeticalByFileName, }, diff --git a/src/main.rs b/src/main.rs index 1e79175..df7639a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,6 +29,7 @@ fn run() -> Result<(), Error> { } else { Color::None }, + apparent_size: opt.apparent_size, sorting: TraversalSorting::None, }; let res = match opt.command { diff --git a/src/options.rs b/src/options.rs index 2aa75d3..4dc1aff 100644 --- a/src/options.rs +++ b/src/options.rs @@ -52,6 +52,10 @@ pub struct Args { #[structopt(short = "f", long = "format")] pub format: Option<ByteFormat>, + /// Display apparent size instead of disk usage. + #[structopt(short = "A", long = "apparent-size")] + pub apparent_size: bool, + /// One or more input files or directories. If unset, we will use all entries in the current working directory. #[structopt(parse(from_os_str))] pub input: Vec<PathBuf>, diff --git a/src/traverse.rs b/src/traverse.rs index b4071d4..c9bb4a9 100644 --- a/src/traverse.rs +++ b/src/traverse.rs @@ -93,7 +93,18 @@ impl Traversal { entry.file_name }; let file_size = match entry.metadata { - Some(Ok(ref m)) if !m.is_dir() => m.len(), + Some(Ok(ref m)) if !m.is_dir() => { + if walk_options.apparent_size { + m.len() + } else { + filesize::file_real_size_fast(&data.name, m) + .unwrap_or_else(|_| { + t.io_errors += 1; + data.metadata_io_error = true; + 0 + }) + } + }, Some(Ok(_)) => 0, Some(Err(_)) => { t.io_errors += 1; |