@@ -13,7 +13,7 @@ use filetime::{FileTime, set_file_times};
1313use std:: fmt:: Debug ;
1414use std:: fs:: File ;
1515use std:: fs:: { self , metadata} ;
16- use std:: path:: { MAIN_SEPARATOR , Path , PathBuf } ;
16+ use std:: path:: { self , Path , PathBuf , MAIN_SEPARATOR } ;
1717use std:: process;
1818use thiserror:: Error ;
1919use uucore:: backup_control:: { self , BackupMode } ;
@@ -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
106109impl 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///
753756fn copy_file ( from : & Path , to : & Path ) -> UResult < ( ) > {
757+ if path:: absolute ( from) ? == path:: absolute ( to) ? {
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 ( ) ,
0 commit comments