Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion src/uu/install/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,16 @@ fn is_new_file_path(path: &Path) -> bool {
.is_none_or(|p| p.as_os_str().is_empty() || p.is_dir())
}

/// Test if the path is a valid target for a single-file install.
///
/// A valid target is a regular file, a path that can be created as a new file,
/// or any existing non-directory entry (including device files, FIFOs, sockets
/// and symlinks). Directories are handled by `copy_files_into_dir`.
#[inline]
fn is_valid_target(path: &Path) -> bool {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest #[inline]'ing this function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in e072f79 — added #[inline] to is_valid_target. cargo test --features install --test tests install (104) + fmt + clippy clean.

path.is_file() || is_new_file_path(path) || path.symlink_metadata().is_ok_and(|m| !m.is_dir())
}

/// Test if the path is an existing directory or ends with a trailing separator.
///
/// Returns true, if one of the conditions above is met; else false.
Expand Down Expand Up @@ -777,7 +787,7 @@ fn standard(mut paths: Vec<OsString>, b: &Behavior) -> UResult<()> {
return Err(InstallError::SameFile(source.clone(), target.clone()).into());
}

if target.is_file() || is_new_file_path(&target) {
if is_valid_target(&target) {
#[cfg(unix)]
if let (Some(ref parent_fd), Some(ref filename)) = (target_parent_fd, target_filename) {
if b.compare && !need_copy(source, &target, b) {
Expand Down
13 changes: 13 additions & 0 deletions tests/by-util/test_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,19 @@ fn test_install_proc_self_mem_as_dst() {
.stderr_contains("cannot remove");
}

#[test]
#[cfg(target_os = "linux")]
fn test_install_dev_full_as_dst() {
let scene = TestScenario::new(util_name!());

scene
.ucmd()
.arg("/dev/null")
.arg("/dev/full")
.fails()
.stderr_contains("cannot remove '/dev/full'");
}

#[test]
fn test_install_backup_nil_same_file() {
let scene = TestScenario::new(util_name!());
Expand Down
Loading