Skip to content

Commit

Permalink
du: add -P/--no-dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Nov 3, 2023
1 parent 1c7a788 commit 29f6631
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mod options {
pub const ONE_FILE_SYSTEM: &str = "one-file-system";
pub const DEREFERENCE: &str = "dereference";
pub const DEREFERENCE_ARGS: &str = "dereference-args";
pub const NO_DEREFERENCE: &str = "no-dereference";
pub const INODES: &str = "inodes";
pub const EXCLUDE: &str = "exclude";
pub const EXCLUDE_FROM: &str = "exclude-from";
Expand Down Expand Up @@ -824,13 +825,14 @@ pub fn uu_app() -> Command {
.help("follow only symlinks that are listed on the command line")
.action(ArgAction::SetTrue)
)
// .arg(
// Arg::new("no-dereference")
// .short('P')
// .long("no-dereference")
// .help("don't follow any symbolic links (this is the default)")
// .action(ArgAction::SetTrue),
// )
.arg(
Arg::new(options::NO_DEREFERENCE)
.short('P')
.long(options::NO_DEREFERENCE)
.help("don't follow any symbolic links (this is the default)")
.overrides_with(options::DEREFERENCE)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new(options::BLOCK_SIZE_1M)
.short('m')
Expand Down
36 changes: 36 additions & 0 deletions tests/by-util/test_du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,42 @@ fn _du_dereference(s: &str) {
}
}

#[cfg(not(windows))]
#[test]
fn test_du_no_dereference() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
let dir = "a_dir";
let symlink = "symlink";

at.mkdir(dir);
at.symlink_dir(dir, symlink);

for arg in ["-P", "--no-dereference"] {
ts.ucmd()
.arg(arg)
.succeeds()
.stdout_contains(dir)
.stdout_does_not_contain(symlink);

// ensure no-dereference "wins"
ts.ucmd()
.arg("--dereference")
.arg(arg)
.succeeds()
.stdout_contains(dir)
.stdout_does_not_contain(symlink);

// ensure dereference "wins"
ts.ucmd()
.arg(arg)
.arg("--dereference")
.succeeds()
.stdout_contains(symlink)
.stdout_does_not_contain(dir);
}
}

#[test]
fn test_du_inodes_basic() {
let ts = TestScenario::new(util_name!());
Expand Down

0 comments on commit 29f6631

Please sign in to comment.