|
1 | 1 | // 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. |
5 | 3 |
|
6 | 4 | // spell-checker:ignore (ToDO) rwxr sourcepath targetpath Isnt uioerror |
7 | 5 |
|
@@ -101,6 +99,9 @@ enum InstallError { |
101 | 99 |
|
102 | 100 | #[error("cannot overwrite directory {} with non-directory {}", .0.quote(), .1.quote())] |
103 | 101 | OverrideDirectoryFailed(PathBuf, PathBuf), |
| 102 | + |
| 103 | + #[error("'{0}' and '{1}' are the same file")] |
| 104 | + SameFile(PathBuf, PathBuf) |
104 | 105 | } |
105 | 106 |
|
106 | 107 | impl UError for InstallError { |
@@ -751,6 +752,10 @@ fn copy_normal_file(from: &Path, to: &Path) -> UResult<()> { |
751 | 752 | /// Returns an empty Result or an error in case of failure. |
752 | 753 | /// |
753 | 754 | 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 | + |
754 | 759 | if to.is_dir() && !from.is_dir() { |
755 | 760 | return Err(InstallError::OverrideDirectoryFailed( |
756 | 761 | to.to_path_buf().clone(), |
|
0 commit comments