File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -1802,7 +1802,13 @@ fn is_forbidden_to_copy_to_same_file(
1802
1802
if options. copy_mode == CopyMode :: SymLink && dest_is_symlink {
1803
1803
return false ;
1804
1804
}
1805
- if dest_is_symlink && source_is_symlink && !options. dereference {
1805
+ // If source and dest are both the same symlink but with different names, then allow the copy.
1806
+ // This can occur, for example, if source and dest are both hardlinks to the same symlink.
1807
+ if dest_is_symlink
1808
+ && source_is_symlink
1809
+ && source. file_name ( ) != dest. file_name ( )
1810
+ && !options. dereference
1811
+ {
1806
1812
return false ;
1807
1813
}
1808
1814
true
Original file line number Diff line number Diff line change @@ -5218,6 +5218,31 @@ mod same_file {
5218
5218
assert_eq ! ( symlink1, at. resolve_link( symlink2) ) ;
5219
5219
}
5220
5220
5221
+ #[ test]
5222
+ fn test_same_symlink_to_itself_no_dereference ( ) {
5223
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
5224
+ let at = & scene. fixtures ;
5225
+ at. write ( FILE_NAME , CONTENTS ) ;
5226
+ at. symlink_file ( FILE_NAME , SYMLINK_NAME ) ;
5227
+ scene
5228
+ . ucmd ( )
5229
+ . args ( & [ "-P" , SYMLINK_NAME , SYMLINK_NAME ] )
5230
+ . fails ( )
5231
+ . stderr_contains ( "are the same file" ) ;
5232
+ }
5233
+
5234
+ #[ test]
5235
+ fn test_same_dangling_symlink_to_itself_no_dereference ( ) {
5236
+ let scene = TestScenario :: new ( util_name ! ( ) ) ;
5237
+ let at = & scene. fixtures ;
5238
+ at. symlink_file ( "nonexistent_file" , SYMLINK_NAME ) ;
5239
+ scene
5240
+ . ucmd ( )
5241
+ . args ( & [ "-P" , SYMLINK_NAME , SYMLINK_NAME ] )
5242
+ . fails ( )
5243
+ . stderr_contains ( "are the same file" ) ;
5244
+ }
5245
+
5221
5246
// the following tests tries to copy file to a hardlink of the same file with
5222
5247
// various options
5223
5248
#[ test]
You can’t perform that action at this time.
0 commit comments