1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

ls: silence clippy warnings if feat_selinx is not set

This commit is contained in:
Jan Scheer 2021-09-22 13:49:08 +02:00
parent 8f229aad87
commit 8cd8c25b0d
No known key found for this signature in database
GPG key ID: C62AD4C29E2B9828

View file

@ -1259,7 +1259,11 @@ impl PathData {
None => OnceCell::new(), None => OnceCell::new(),
}; };
let security_context = get_security_context(config, &p_buf, must_dereference); let security_context = if config.context {
get_security_context(config, &p_buf, must_dereference)
} else {
String::new()
};
Self { Self {
md: OnceCell::new(), md: OnceCell::new(),
@ -2089,44 +2093,41 @@ fn display_symlink_count(metadata: &Metadata) -> String {
// This returns the SELinux security context as UTF8 `String`. // This returns the SELinux security context as UTF8 `String`.
// In the long term this should be changed to `OsStr`, see discussions at #2621/#2656 // In the long term this should be changed to `OsStr`, see discussions at #2621/#2656
fn get_security_context(config: &Config, p_buf: &PathBuf, must_dereference: bool) -> String { #[allow(unused_variables)]
fn get_security_context(config: &Config, p_buf: &Path, must_dereference: bool) -> String {
let substitute_string = "?".to_string(); let substitute_string = "?".to_string();
if config.context { if config.selinux_supported {
if config.selinux_supported { #[cfg(feature = "selinux")]
#[cfg(feature = "selinux")] {
{ match selinux::SecurityContext::of_path(p_buf, must_dereference, false) {
match selinux::SecurityContext::of_path(p_buf, must_dereference, false) { Err(_r) => {
Err(_r) => { // TODO: show the actual reason why it failed
// TODO: show the actual reason why it failed show_warning!("failed to get security context of: {}", p_buf.quote());
show_warning!("failed to get security context of: {}", p_buf.quote()); substitute_string
substitute_string }
} Ok(None) => substitute_string,
Ok(None) => substitute_string, Ok(Some(context)) => {
Ok(Some(context)) => { let mut context = context.as_bytes();
let mut context = context.as_bytes(); if context.ends_with(&[0]) {
if context.ends_with(&[0]) { // TODO: replace with `strip_prefix()` when MSRV >= 1.51
// TODO: replace with `strip_prefix()` when MSRV >= 1.51 context = &context[..context.len() - 1]
context = &context[..context.len() - 1] };
}; String::from_utf8(context.to_vec()).unwrap_or_else(|e| {
String::from_utf8(context.to_vec()).unwrap_or_else(|e| { show_warning!(
show_warning!( "getting security context of: {}: {}",
"getting security context of: {}: {}", p_buf.quote(),
p_buf.quote(), e.to_string()
e.to_string() );
); String::from_utf8_lossy(context).into_owned()
String::from_utf8_lossy(context).into_owned() })
})
}
} }
} }
#[cfg(not(feature = "selinux"))] }
{ #[cfg(not(feature = "selinux"))]
substitute_string {
}
} else {
substitute_string substitute_string
} }
} else { } else {
String::new() substitute_string
} }
} }