Skip to content

Commit 3ce8c0c

Browse files
authored
check if paths are to/from device
1 parent db25551 commit 3ce8c0c

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

‎src/uu/install/src/install.rs‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,21 @@ fn copy_file_safe(from: &Path, to_parent_fd: &DirFd, to_filename: &std::ffi::OsS
926926
Ok(())
927927
}
928928

929+
// checks if a path is symlink to a device e.g /dev/stdin
930+
fn is_path_device(path: &Path) -> bool {
931+
#[cfg(unix)]
932+
use std::os::unix::fs::FileTypeExt;
933+
{
934+
if let Ok(metadata) = metadata(path) {
935+
let file_type = metadata.file_type();
936+
if file_type.is_fifo() {
937+
return true;
938+
}
939+
}
940+
}
941+
false
942+
}
943+
929944
/// Copy a file from one path to another. Handles the certain cases of special
930945
/// files (e.g character specials).
931946
///
@@ -940,12 +955,13 @@ fn copy_file_safe(from: &Path, to_parent_fd: &DirFd, to_filename: &std::ffi::OsS
940955
///
941956
fn copy_file(from: &Path, to: &Path) -> UResult<()> {
942957
use std::os::unix::fs::OpenOptionsExt;
943-
if let Ok(to_abs) = to.canonicalize()
944-
&& from.canonicalize()? == to_abs
945-
{
946-
return Err(InstallError::SameFile(from.to_path_buf(), to.to_path_buf()).into());
958+
if !is_path_device(from) && !is_path_device(to) {
959+
if let Ok(to_abs) = to.canonicalize()
960+
&& from.canonicalize()? == to_abs
961+
{
962+
return Err(InstallError::SameFile(from.to_path_buf(), to.to_path_buf()).into());
963+
}
947964
}
948-
949965
if to.is_dir() && !from.is_dir() {
950966
return Err(InstallError::OverrideDirectoryFailed(
951967
to.to_path_buf().clone(),

0 commit comments

Comments
 (0)