Merge pull request #5491 from cakebaker/du_no_dereference

du: add --no-dereference
This commit is contained in:
Sylvestre Ledru 2023-11-04 08:56:32 +01:00 committed by GitHub
commit 347bded33f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 7 deletions

View file

@ -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";
@ -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')

View file

@ -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!());