Skip to content

Commit

Permalink
Add support for real/apparent size
Browse files Browse the repository at this point in the history
  • Loading branch information
Freaky committed Feb 22, 2020
1 parent 2495390 commit d86e1e0
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions src/interactive/app_test/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn run() -> Result<(), Error> {
} else {
Color::None
},
apparent_size: opt.apparent_size,
sorting: TraversalSorting::None,
};
let res = match opt.command {
Expand Down
4 changes: 4 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
13 changes: 12 additions & 1 deletion src/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d86e1e0

Please sign in to comment.