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