Skip to content

Commit 433e18e

Browse files
authored
Merge pull request #8288 from cakebaker/install_simplify_return_type
install: use `bool` as return type of `need_copy`
2 parents 19103ee + 348bd3d commit 433e18e

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/uu/install/src/install.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ fn preserve_timestamps(from: &Path, to: &Path) -> UResult<()> {
956956
/// If the copy system call fails, we print a verbose error and return an empty error value.
957957
///
958958
fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> {
959-
if b.compare && !need_copy(from, to, b)? {
959+
if b.compare && !need_copy(from, to, b) {
960960
return Ok(());
961961
}
962962
// Declare the path here as we may need it for the verbose output below.
@@ -1050,23 +1050,23 @@ fn needs_copy_for_ownership(to: &Path, to_meta: &fs::Metadata) -> bool {
10501050
///
10511051
/// Crashes the program if a nonexistent owner or group is specified in _b_.
10521052
///
1053-
fn need_copy(from: &Path, to: &Path, b: &Behavior) -> UResult<bool> {
1053+
fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
10541054
// Attempt to retrieve metadata for the source file.
10551055
// If this fails, assume the file needs to be copied.
10561056
let Ok(from_meta) = metadata(from) else {
1057-
return Ok(true);
1057+
return true;
10581058
};
10591059

10601060
// Attempt to retrieve metadata for the destination file.
10611061
// If this fails, assume the file needs to be copied.
10621062
let Ok(to_meta) = metadata(to) else {
1063-
return Ok(true);
1063+
return true;
10641064
};
10651065

10661066
// Check if the destination is a symlink (should always be replaced)
10671067
if let Ok(to_symlink_meta) = fs::symlink_metadata(to) {
10681068
if to_symlink_meta.file_type().is_symlink() {
1069-
return Ok(true);
1069+
return true;
10701070
}
10711071
}
10721072

@@ -1082,53 +1082,53 @@ fn need_copy(from: &Path, to: &Path, b: &Behavior) -> UResult<bool> {
10821082
|| from_meta.mode() & extra_mode != 0
10831083
|| to_meta.mode() & extra_mode != 0
10841084
{
1085-
return Ok(true);
1085+
return true;
10861086
}
10871087

10881088
// Check if the mode of the destination file differs from the specified mode.
10891089
if b.mode() != to_meta.mode() & all_modes {
1090-
return Ok(true);
1090+
return true;
10911091
}
10921092

10931093
// Check if either the source or destination is not a file.
10941094
if !from_meta.is_file() || !to_meta.is_file() {
1095-
return Ok(true);
1095+
return true;
10961096
}
10971097

10981098
// Check if the file sizes differ.
10991099
if from_meta.len() != to_meta.len() {
1100-
return Ok(true);
1100+
return true;
11011101
}
11021102

11031103
#[cfg(feature = "selinux")]
11041104
if b.preserve_context && contexts_differ(from, to) {
1105-
return Ok(true);
1105+
return true;
11061106
}
11071107

11081108
// TODO: if -P (#1809) and from/to contexts mismatch, return true.
11091109

11101110
// Check if the owner ID is specified and differs from the destination file's owner.
11111111
if let Some(owner_id) = b.owner_id {
11121112
if owner_id != to_meta.uid() {
1113-
return Ok(true);
1113+
return true;
11141114
}
11151115
}
11161116

11171117
// Check if the group ID is specified and differs from the destination file's group.
11181118
if let Some(group_id) = b.group_id {
11191119
if group_id != to_meta.gid() {
1120-
return Ok(true);
1120+
return true;
11211121
}
11221122
} else if needs_copy_for_ownership(to, &to_meta) {
1123-
return Ok(true);
1123+
return true;
11241124
}
11251125

11261126
// Check if the contents of the source and destination files differ.
11271127
if !diff(from.to_str().unwrap(), to.to_str().unwrap()) {
1128-
return Ok(true);
1128+
return true;
11291129
}
11301130

1131-
Ok(false)
1131+
false
11321132
}
11331133

11341134
#[cfg(feature = "selinux")]

0 commit comments

Comments
 (0)