Skip to content

Commit 1ceb79e

Browse files
committed
install: fixes issue uutils#7795
1 parent 18db15e commit 1ceb79e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/uu/install/src/install.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ enum InstallError {
101101

102102
#[error("cannot overwrite directory {} with non-directory {}", .0.quote(), .1.quote())]
103103
OverrideDirectoryFailed(PathBuf, PathBuf),
104+
105+
#[error("'{0}' and '{1}' are the same file")]
106+
SameFile(PathBuf, PathBuf),
104107
}
105108

106109
impl UError for InstallError {
@@ -751,6 +754,10 @@ fn copy_normal_file(from: &Path, to: &Path) -> UResult<()> {
751754
/// Returns an empty Result or an error in case of failure.
752755
///
753756
fn copy_file(from: &Path, to: &Path) -> UResult<()> {
757+
if from.canonicalize()? == to.parent().unwrap().canonicalize()?.join(from) {
758+
return Err(InstallError::SameFile(from.to_path_buf(), to.to_path_buf()).into());
759+
}
760+
754761
if to.is_dir() && !from.is_dir() {
755762
return Err(InstallError::OverrideDirectoryFailed(
756763
to.to_path_buf().clone(),

tests/by-util/test_install.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,3 +1778,15 @@ fn test_install_failing_copy_file_to_target_contain_subdir_with_same_name() {
17781778
.fails()
17791779
.stderr_contains("cannot overwrite directory");
17801780
}
1781+
1782+
#[test]
1783+
fn test_install_same_file() {
1784+
let (at, mut ucmd) = at_and_ucmd!();
1785+
let file = "file";
1786+
1787+
at.touch(file);
1788+
ucmd.arg(file)
1789+
.arg(".")
1790+
.fails()
1791+
.stderr_contains("'file' and './file' are the same file");
1792+
}

0 commit comments

Comments
 (0)