Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@
/// If the copy system call fails, we print a verbose error and return an empty error value.
///
fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> {
if b.compare && !need_copy(from, to, b)? {
if b.compare && !need_copy(from, to, b) {
return Ok(());
}
// Declare the path here as we may need it for the verbose output below.
Expand Down Expand Up @@ -1050,23 +1050,23 @@
///
/// Crashes the program if a nonexistent owner or group is specified in _b_.
///
fn need_copy(from: &Path, to: &Path, b: &Behavior) -> UResult<bool> {
fn need_copy(from: &Path, to: &Path, b: &Behavior) -> bool {
// Attempt to retrieve metadata for the source file.
// If this fails, assume the file needs to be copied.
let Ok(from_meta) = metadata(from) else {
return Ok(true);
return true;

Check warning on line 1057 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L1057

Added line #L1057 was not covered by tests
};

// Attempt to retrieve metadata for the destination file.
// If this fails, assume the file needs to be copied.
let Ok(to_meta) = metadata(to) else {
return Ok(true);
return true;
};

// Check if the destination is a symlink (should always be replaced)
if let Ok(to_symlink_meta) = fs::symlink_metadata(to) {
if to_symlink_meta.file_type().is_symlink() {
return Ok(true);
return true;
}
}

Expand All @@ -1082,53 +1082,53 @@
|| from_meta.mode() & extra_mode != 0
|| to_meta.mode() & extra_mode != 0
{
return Ok(true);
return true;
}

// Check if the mode of the destination file differs from the specified mode.
if b.mode() != to_meta.mode() & all_modes {
return Ok(true);
return true;
}

// Check if either the source or destination is not a file.
if !from_meta.is_file() || !to_meta.is_file() {
return Ok(true);
return true;

Check warning on line 1095 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L1095

Added line #L1095 was not covered by tests
}

// Check if the file sizes differ.
if from_meta.len() != to_meta.len() {
return Ok(true);
return true;
}

#[cfg(feature = "selinux")]
if b.preserve_context && contexts_differ(from, to) {
return Ok(true);
return true;
}

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

// Check if the owner ID is specified and differs from the destination file's owner.
if let Some(owner_id) = b.owner_id {
if owner_id != to_meta.uid() {
return Ok(true);
return true;

Check warning on line 1113 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L1113

Added line #L1113 was not covered by tests
}
}

// Check if the group ID is specified and differs from the destination file's group.
if let Some(group_id) = b.group_id {
if group_id != to_meta.gid() {
return Ok(true);
return true;

Check warning on line 1120 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L1120

Added line #L1120 was not covered by tests
}
} else if needs_copy_for_ownership(to, &to_meta) {
return Ok(true);
return true;

Check warning on line 1123 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L1123

Added line #L1123 was not covered by tests
}

// Check if the contents of the source and destination files differ.
if !diff(from.to_str().unwrap(), to.to_str().unwrap()) {
return Ok(true);
return true;

Check warning on line 1128 in src/uu/install/src/install.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/install/src/install.rs#L1128

Added line #L1128 was not covered by tests
}

Ok(false)
false
}

#[cfg(feature = "selinux")]
Expand Down
Loading