File tree Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Expand file tree Collapse file tree 1 file changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -1524,11 +1524,40 @@ fn is_forbidden_to_copy_to_same_file(
15241524) -> bool {
15251525 // TODO To match the behavior of GNU cp, we also need to check
15261526 // that the file is a regular file.
1527+ // only disable dereference if both source and dest is symlink and dereference flag is disabled
15271528 let dereference_to_compare =
1528- options. dereference ( source_in_command_line) || !source. is_symlink ( ) ;
1529- paths_refer_to_same_file ( source, dest, dereference_to_compare)
1530- && !( options. force ( ) && options. backup != BackupMode :: NoBackup )
1531- && !( dest. is_symlink ( ) && options. backup != BackupMode :: NoBackup )
1529+ options. dereference ( source_in_command_line) || ( !source. is_symlink ( ) || !dest. is_symlink ( ) ) ;
1530+ if !paths_refer_to_same_file ( source, dest, dereference_to_compare) {
1531+ return false ;
1532+ }
1533+ if options. backup != BackupMode :: NoBackup {
1534+ if options. force ( ) {
1535+ if !source. is_symlink ( ) {
1536+ return false ;
1537+ } ;
1538+ }
1539+ if source. is_symlink ( ) && !options. dereference {
1540+ return false ;
1541+ }
1542+ if dest. is_symlink ( ) {
1543+ return false ;
1544+ }
1545+ }
1546+ if options. copy_mode == CopyMode :: Link {
1547+ if options. force ( ) {
1548+ return false ;
1549+ }
1550+ if source. is_symlink ( ) {
1551+ return false ;
1552+ }
1553+ }
1554+ if options. copy_mode == CopyMode :: SymLink {
1555+ if options. force ( ) {
1556+ return false ;
1557+ }
1558+ }
1559+
1560+ true
15321561}
15331562
15341563/// Back up, remove, or leave intact the destination file, depending on the options.
You can’t perform that action at this time.
0 commit comments