File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -1502,7 +1502,7 @@ fn copy_source(
15021502 copied_files : & mut HashMap < FileInformation , PathBuf > ,
15031503) -> CopyResult < ( ) > {
15041504 let source_path = Path :: new ( & source) ;
1505- if source_path. is_dir ( ) {
1505+ if source_path. is_dir ( ) && ( options . dereference || !source_path . is_symlink ( ) ) {
15061506 // Copy as directory
15071507 copy_directory (
15081508 progress_bar,
Original file line number Diff line number Diff line change @@ -6706,3 +6706,23 @@ fn test_cp_preserve_context_root() {
67066706 print ! ( "Test skipped; requires root user" ) ;
67076707 }
67086708}
6709+
6710+ #[ test]
6711+ #[ cfg( not( windows) ) ]
6712+ fn test_cp_no_dereference_symlink_with_parents ( ) {
6713+ let ts = TestScenario :: new ( util_name ! ( ) ) ;
6714+ let at = & ts. fixtures ;
6715+ at. mkdir ( "directory" ) ;
6716+ at. symlink_file ( "directory" , "symlink-to-directory" ) ;
6717+
6718+ ts. ucmd ( )
6719+ . args ( & [ "--parents" , "--no-dereference" , "symlink-to-directory" , "x" ] )
6720+ . fails ( )
6721+ . stderr_contains ( "with --parents, the destination must be a directory" ) ;
6722+
6723+ at. mkdir ( "x" ) ;
6724+ ts. ucmd ( )
6725+ . args ( & [ "--parents" , "--no-dereference" , "symlink-to-directory" , "x" ] )
6726+ . succeeds ( ) ;
6727+ assert_eq ! ( at. resolve_link( "x/symlink-to-directory" ) , "directory" ) ;
6728+ }
You can’t perform that action at this time.
0 commit comments