mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
chcon: allow overriding between --dereference and --no-dereference
This commit is contained in:
parent
6c29ed037b
commit
dbfd4d80ee
2 changed files with 51 additions and 1 deletions
|
@ -163,7 +163,7 @@ pub fn uu_app() -> Command {
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new(options::dereference::DEREFERENCE)
|
Arg::new(options::dereference::DEREFERENCE)
|
||||||
.long(options::dereference::DEREFERENCE)
|
.long(options::dereference::DEREFERENCE)
|
||||||
.conflicts_with(options::dereference::NO_DEREFERENCE)
|
.overrides_with(options::dereference::NO_DEREFERENCE)
|
||||||
.help(
|
.help(
|
||||||
"Affect the referent of each symbolic link (this is the default), \
|
"Affect the referent of each symbolic link (this is the default), \
|
||||||
rather than the symbolic link itself.",
|
rather than the symbolic link itself.",
|
||||||
|
|
|
@ -88,6 +88,33 @@ fn valid_context_on_valid_symlink() {
|
||||||
assert_eq!(get_file_context(dir.plus("a.tmp")).unwrap(), a_context);
|
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]
|
#[test]
|
||||||
fn valid_context_on_broken_symlink() {
|
fn valid_context_on_broken_symlink() {
|
||||||
let (dir, mut cmd) = at_and_ucmd!();
|
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]
|
#[test]
|
||||||
fn valid_context_with_prior_xattributes() {
|
fn valid_context_with_prior_xattributes() {
|
||||||
let (dir, mut cmd) = at_and_ucmd!();
|
let (dir, mut cmd) = at_and_ucmd!();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue