diff --git a/src/uu/chcon/src/chcon.rs b/src/uu/chcon/src/chcon.rs index ec111c853..ddbaec98b 100644 --- a/src/uu/chcon/src/chcon.rs +++ b/src/uu/chcon/src/chcon.rs @@ -163,7 +163,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(options::dereference::DEREFERENCE) .long(options::dereference::DEREFERENCE) - .conflicts_with(options::dereference::NO_DEREFERENCE) + .overrides_with(options::dereference::NO_DEREFERENCE) .help( "Affect the referent of each symbolic link (this is the default), \ rather than the symbolic link itself.", diff --git a/tests/by-util/test_chcon.rs b/tests/by-util/test_chcon.rs index 71405e451..b28996b2b 100644 --- a/tests/by-util/test_chcon.rs +++ b/tests/by-util/test_chcon.rs @@ -88,6 +88,33 @@ fn valid_context_on_valid_symlink() { assert_eq!(get_file_context(dir.plus("a.tmp")).unwrap(), a_context); } +#[test] +fn valid_context_on_valid_symlink_override_dereference() { + let (dir, mut cmd) = at_and_ucmd!(); + dir.touch("a.tmp"); + dir.symlink_file("a.tmp", "la.tmp"); + + let a_context = get_file_context(dir.plus("a.tmp")).unwrap(); + let la_context = get_file_context(dir.plus("la.tmp")).unwrap(); + let new_a_context = "guest_u:object_r:etc_t:s0:c42"; + assert_ne!(a_context.as_deref(), Some(new_a_context)); + assert_ne!(la_context.as_deref(), Some(new_a_context)); + + cmd.args(&[ + "--verbose", + "--no-dereference", + "--dereference", + new_a_context, + ]) + .arg(dir.plus("la.tmp")) + .succeeds(); + assert_eq!( + get_file_context(dir.plus("a.tmp")).unwrap().as_deref(), + Some(new_a_context) + ); + assert_eq!(get_file_context(dir.plus("la.tmp")).unwrap(), la_context); +} + #[test] fn valid_context_on_broken_symlink() { let (dir, mut cmd) = at_and_ucmd!(); @@ -104,6 +131,29 @@ fn valid_context_on_broken_symlink() { ); } +#[test] +fn valid_context_on_broken_symlink_after_deref() { + let (dir, mut cmd) = at_and_ucmd!(); + dir.symlink_file("a.tmp", "la.tmp"); + + let la_context = get_file_context(dir.plus("la.tmp")).unwrap(); + let new_la_context = "guest_u:object_r:etc_t:s0:c42"; + assert_ne!(la_context.as_deref(), Some(new_la_context)); + + cmd.args(&[ + "--verbose", + "--dereference", + "--no-dereference", + new_la_context, + ]) + .arg(dir.plus("la.tmp")) + .succeeds(); + assert_eq!( + get_file_context(dir.plus("la.tmp")).unwrap().as_deref(), + Some(new_la_context) + ); +} + #[test] fn valid_context_with_prior_xattributes() { let (dir, mut cmd) = at_and_ucmd!();