clippy: fix warnings from unnecessary_unwrap lint

This commit is contained in:
Daniel Hofstetter 2025-08-07 15:06:19 +02:00
parent 454bdcb039
commit 45cd3e8e56
2 changed files with 50 additions and 52 deletions

View file

@ -362,11 +362,13 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
}
// Check if compare is used with non-permission mode bits
if compare && specified_mode.is_some() {
let mode = specified_mode.unwrap();
let non_permission_bits = 0o7000; // setuid, setgid, sticky bits
if mode & non_permission_bits != 0 {
show_error!("{}", translate!("install-warning-compare-ignored"));
// TODO use a let chain once we have a MSRV of 1.88 or greater
if compare {
if let Some(mode) = specified_mode {
let non_permission_bits = 0o7000; // setuid, setgid, sticky bits
if mode & non_permission_bits != 0 {
show_error!("{}", translate!("install-warning-compare-ignored"));
}
}
}

View file

@ -474,57 +474,53 @@ mod tests {
let result = get_selinux_security_context(path, false);
if result.is_ok() {
let context = result.unwrap();
println!("Retrieved SELinux context: {context}");
match result {
Ok(context) => {
println!("Retrieved SELinux context: {context}");
assert!(
is_selinux_enabled(),
"Got a successful context result but SELinux is not enabled"
);
if !context.is_empty() {
assert!(
context.contains(':'),
"SELinux context '{context}' doesn't match expected format"
is_selinux_enabled(),
"Got a successful context result but SELinux is not enabled"
);
if !context.is_empty() {
assert!(
context.contains(':'),
"SELinux context '{context}' doesn't match expected format"
);
}
}
Err(SeLinuxError::SELinuxNotEnabled) => {
assert!(
!is_selinux_enabled(),
"Got SELinuxNotEnabled error, but is_selinux_enabled() returned true"
);
}
} else {
let err = result.unwrap_err();
match err {
SeLinuxError::SELinuxNotEnabled => {
assert!(
!is_selinux_enabled(),
"Got SELinuxNotEnabled error, but is_selinux_enabled() returned true"
);
}
SeLinuxError::ContextRetrievalFailure(e) => {
assert!(
is_selinux_enabled(),
"Got ContextRetrievalFailure when SELinux is not enabled"
);
assert!(!e.is_empty(), "Error message should not be empty");
println!("Context retrieval failure: {e}");
}
SeLinuxError::ContextConversionFailure(ctx, e) => {
assert!(
is_selinux_enabled(),
"Got ContextConversionFailure when SELinux is not enabled"
);
assert!(!e.is_empty(), "Error message should not be empty");
println!("Context conversion failure for '{ctx}': {e}");
}
SeLinuxError::ContextSetFailure(ctx, e) => {
assert!(!e.is_empty(), "Error message should not be empty");
println!("Context conversion failure for '{ctx}': {e}");
}
SeLinuxError::FileOpenFailure(e) => {
assert!(
Path::new(path).exists(),
"File open failure occurred despite file being created: {e}"
);
}
Err(SeLinuxError::ContextRetrievalFailure(e)) => {
assert!(
is_selinux_enabled(),
"Got ContextRetrievalFailure when SELinux is not enabled"
);
assert!(!e.is_empty(), "Error message should not be empty");
println!("Context retrieval failure: {e}");
}
Err(SeLinuxError::ContextConversionFailure(ctx, e)) => {
assert!(
is_selinux_enabled(),
"Got ContextConversionFailure when SELinux is not enabled"
);
assert!(!e.is_empty(), "Error message should not be empty");
println!("Context conversion failure for '{ctx}': {e}");
}
Err(SeLinuxError::ContextSetFailure(ctx, e)) => {
assert!(!e.is_empty(), "Error message should not be empty");
println!("Context conversion failure for '{ctx}': {e}");
}
Err(SeLinuxError::FileOpenFailure(e)) => {
assert!(
Path::new(path).exists(),
"File open failure occurred despite file being created: {e}"
);
}
}
}