From 095eced4be525d939216b879a789baf02add7547 Mon Sep 17 00:00:00 2001 From: Matei Mantu <66641453+mtimaN@users.noreply.github.com> Date: Mon, 26 Feb 2024 12:01:50 +0200 Subject: [PATCH] chmod: Fix chmod -c --reference reporting when no change is made (#6016) * Make fperm hold 6 digit octal permission. Set it to 4 digits when displaying * Add test * Make every permission 4 octal digits * Change test name to be more suggestive * chmod: merge two args in test --------- Co-authored-by: Daniel Hofstetter --- src/uu/chmod/src/chmod.rs | 2 +- tests/by-util/test_chmod.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index 31663b1af..3c387b5f8 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -101,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let recursive = matches.get_flag(options::RECURSIVE); let fmode = match matches.get_one::(options::REFERENCE) { Some(fref) => match fs::metadata(fref) { - Ok(meta) => Some(meta.mode()), + Ok(meta) => Some(meta.mode() & 0o7777), Err(err) => { return Err(USimpleError::new( 1, diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index be730a8c0..35197f85e 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -645,6 +645,20 @@ fn test_quiet_n_verbose_used_multiple_times() { .succeeds(); } +#[test] +fn test_changes_from_identical_reference() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + at.touch("file"); + scene + .ucmd() + .arg("-c") + .arg("--reference=file") + .arg("file") + .succeeds() + .no_stdout(); +} + #[test] fn test_gnu_invalid_mode() { let scene = TestScenario::new(util_name!());