@@ -4675,6 +4675,7 @@ fn test_cp_no_dereference_attributes_only_with_symlink() {
46754675/// contains the test for cp when the source and destination points to the same file
46764676mod same_file {
46774677
4678+ use std:: os:: unix:: fs:: MetadataExt ;
46784679 use uutests:: util:: TestScenario ;
46794680 use uutests:: util_name;
46804681
@@ -5594,6 +5595,26 @@ mod same_file {
55945595 assert_eq ! ( FILE_NAME , at. resolve_link( hardlink_to_symlink) ) ;
55955596 assert_eq ! ( at. read( FILE_NAME ) , CONTENTS ) ;
55965597 }
5598+
5599+ #[ test]
5600+ fn test_hardlink_of_symlink_to_hardlink_of_same_symlink_with_option_no_deref ( ) {
5601+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
5602+ let at = & scene. fixtures ;
5603+ let hardlink1 = "hardlink_to_symlink_1" ;
5604+ let hardlink2 = "hardlink_to_symlink_2" ;
5605+ at. write ( FILE_NAME , CONTENTS ) ;
5606+ at. symlink_file ( FILE_NAME , SYMLINK_NAME ) ;
5607+ at. hard_link ( SYMLINK_NAME , hardlink1) ;
5608+ at. hard_link ( SYMLINK_NAME , hardlink2) ;
5609+ let ino = at. symlink_metadata ( hardlink1) . ino ( ) ;
5610+ assert_eq ! ( ino, at. symlink_metadata( hardlink2) . ino( ) ) ; // Sanity check
5611+ scene. ucmd ( ) . args ( & [ "-P" , hardlink1, hardlink2] ) . succeeds ( ) ;
5612+ assert ! ( at. file_exists( FILE_NAME ) ) ;
5613+ assert ! ( at. symlink_exists( SYMLINK_NAME ) ) ;
5614+ // If hardlink a and b point to the same symlink, then cp a b doesn't create a new file
5615+ assert_eq ! ( ino, at. symlink_metadata( hardlink1) . ino( ) ) ;
5616+ assert_eq ! ( ino, at. symlink_metadata( hardlink2) . ino( ) ) ;
5617+ }
55975618}
55985619
55995620// the following tests are for how the cp should behave when the source is a symlink
0 commit comments