Skip to content

Commit ae787ef

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

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/uu/install/src/install.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// This file is part of the uutils coreutils package.
2-
//
3-
// For the full copyright and license information, please view the LICENSE
4-
// file that was distributed with this source code.
2+
// For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
53

64
// spell-checker:ignore (ToDO) rwxr sourcepath targetpath Isnt uioerror
75

@@ -101,6 +99,9 @@ enum InstallError {
10199

102100
#[error("cannot overwrite directory {} with non-directory {}", .0.quote(), .1.quote())]
103101
OverrideDirectoryFailed(PathBuf, PathBuf),
102+
103+
#[error("'{0}' and '{1}' are the same file")]
104+
SameFile(PathBuf, PathBuf)
104105
}
105106

106107
impl UError for InstallError {
@@ -751,6 +752,10 @@ fn copy_normal_file(from: &Path, to: &Path) -> UResult<()> {
751752
/// Returns an empty Result or an error in case of failure.
752753
///
753754
fn copy_file(from: &Path, to: &Path) -> UResult<()> {
755+
if from.canonicalize()? == to.canonicalize()? {
756+
return Err(InstallError::SameFile(from.to_path_buf(), to.to_path_buf()).into());
757+
}
758+
754759
if to.is_dir() && !from.is_dir() {
755760
return Err(InstallError::OverrideDirectoryFailed(
756761
to.to_path_buf().clone(),

0 commit comments

Comments
 (0)