Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

du: add --no-dereference #5491

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading