Skip to content

Commit 45cd3e8

Browse files
committed
clippy: fix warnings from unnecessary_unwrap lint
1 parent 454bdcb commit 45cd3e8

File tree

2 files changed

+47
-49
lines changed

2 files changed

+47
-49
lines changed

src/uu/install/src/install.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,13 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
362362
}
363363

364364
// Check if compare is used with non-permission mode bits
365-
if compare && specified_mode.is_some() {
366-
let mode = specified_mode.unwrap();
367-
let non_permission_bits = 0o7000; // setuid, setgid, sticky bits
368-
if mode & non_permission_bits != 0 {
369-
show_error!("{}", translate!("install-warning-compare-ignored"));
365+
// TODO use a let chain once we have a MSRV of 1.88 or greater
366+
if compare {
367+
if let Some(mode) = specified_mode {
368+
let non_permission_bits = 0o7000; // setuid, setgid, sticky bits
369+
if mode & non_permission_bits != 0 {
370+
show_error!("{}", translate!("install-warning-compare-ignored"));
371+
}
370372
}
371373
}
372374

src/uucore/src/lib/features/selinux.rs

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -474,58 +474,54 @@ mod tests {
474474

475475
let result = get_selinux_security_context(path, false);
476476

477-
if result.is_ok() {
478-
let context = result.unwrap();
479-
println!("Retrieved SELinux context: {context}");
480-
481-
assert!(
482-
is_selinux_enabled(),
483-
"Got a successful context result but SELinux is not enabled"
484-
);
477+
match result {
478+
Ok(context) => {
479+
println!("Retrieved SELinux context: {context}");
485480

486-
if !context.is_empty() {
487481
assert!(
488-
context.contains(':'),
489-
"SELinux context '{context}' doesn't match expected format"
482+
is_selinux_enabled(),
483+
"Got a successful context result but SELinux is not enabled"
490484
);
491-
}
492-
} else {
493-
let err = result.unwrap_err();
494485

495-
match err {
496-
SeLinuxError::SELinuxNotEnabled => {
486+
if !context.is_empty() {
497487
assert!(
498-
!is_selinux_enabled(),
499-
"Got SELinuxNotEnabled error, but is_selinux_enabled() returned true"
500-
);
501-
}
502-
SeLinuxError::ContextRetrievalFailure(e) => {
503-
assert!(
504-
is_selinux_enabled(),
505-
"Got ContextRetrievalFailure when SELinux is not enabled"
506-
);
507-
assert!(!e.is_empty(), "Error message should not be empty");
508-
println!("Context retrieval failure: {e}");
509-
}
510-
SeLinuxError::ContextConversionFailure(ctx, e) => {
511-
assert!(
512-
is_selinux_enabled(),
513-
"Got ContextConversionFailure when SELinux is not enabled"
514-
);
515-
assert!(!e.is_empty(), "Error message should not be empty");
516-
println!("Context conversion failure for '{ctx}': {e}");
517-
}
518-
SeLinuxError::ContextSetFailure(ctx, e) => {
519-
assert!(!e.is_empty(), "Error message should not be empty");
520-
println!("Context conversion failure for '{ctx}': {e}");
521-
}
522-
SeLinuxError::FileOpenFailure(e) => {
523-
assert!(
524-
Path::new(path).exists(),
525-
"File open failure occurred despite file being created: {e}"
488+
context.contains(':'),
489+
"SELinux context '{context}' doesn't match expected format"
526490
);
527491
}
528492
}
493+
Err(SeLinuxError::SELinuxNotEnabled) => {
494+
assert!(
495+
!is_selinux_enabled(),
496+
"Got SELinuxNotEnabled error, but is_selinux_enabled() returned true"
497+
);
498+
}
499+
Err(SeLinuxError::ContextRetrievalFailure(e)) => {
500+
assert!(
501+
is_selinux_enabled(),
502+
"Got ContextRetrievalFailure when SELinux is not enabled"
503+
);
504+
assert!(!e.is_empty(), "Error message should not be empty");
505+
println!("Context retrieval failure: {e}");
506+
}
507+
Err(SeLinuxError::ContextConversionFailure(ctx, e)) => {
508+
assert!(
509+
is_selinux_enabled(),
510+
"Got ContextConversionFailure when SELinux is not enabled"
511+
);
512+
assert!(!e.is_empty(), "Error message should not be empty");
513+
println!("Context conversion failure for '{ctx}': {e}");
514+
}
515+
Err(SeLinuxError::ContextSetFailure(ctx, e)) => {
516+
assert!(!e.is_empty(), "Error message should not be empty");
517+
println!("Context conversion failure for '{ctx}': {e}");
518+
}
519+
Err(SeLinuxError::FileOpenFailure(e)) => {
520+
assert!(
521+
Path::new(path).exists(),
522+
"File open failure occurred despite file being created: {e}"
523+
);
524+
}
529525
}
530526
}
531527

0 commit comments

Comments
 (0)