@@ -453,6 +453,39 @@ pub fn copy_dir<T: AsRef<Path>>(from: T, to: T, options: &CopyDirOptions) -> Res
453
453
fs:: create_dir_all ( & destination)
454
454
. path_context ( & destination, "failed to create directory" ) ?;
455
455
copy_dir ( entry. path ( ) , destination, options) ?;
456
+ } else if entry. file_type ( ) ?. is_symlink ( ) {
457
+ let target = fs:: read_link ( & entry_path)
458
+ . path_context ( & entry_path, "failed to read symlink target" ) ?;
459
+ #[ cfg( unix) ]
460
+ {
461
+ if target. is_absolute ( ) && target. starts_with ( from) {
462
+ symlink_file ( target. strip_prefix ( from) . unwrap ( ) , & destination)
463
+ . path_context ( & destination, "failed to create symlink" ) ?;
464
+ } else {
465
+ symlink_file ( target, & destination)
466
+ . path_context ( & destination, "failed to create symlink" ) ?;
467
+ }
468
+ }
469
+ #[ cfg( windows) ]
470
+ {
471
+ if target. is_absolute ( ) && target. starts_with ( from) {
472
+ if target. is_dir ( ) {
473
+ symlink_dir ( target. strip_prefix ( from) . unwrap ( ) , & destination)
474
+ . path_context ( & destination, "failed to create symlink" ) ?;
475
+ } else {
476
+ symlink_file ( target. strip_prefix ( from) . unwrap ( ) , & destination)
477
+ . path_context ( & destination, "failed to create symlink" ) ?;
478
+ }
479
+ } else {
480
+ if target. is_dir ( ) {
481
+ symlink_dir ( target, & destination)
482
+ . path_context ( & destination, "failed to create symlink" ) ?;
483
+ } else {
484
+ symlink_file ( target, & destination)
485
+ . path_context ( & destination, "failed to create symlink" ) ?;
486
+ }
487
+ }
488
+ }
456
489
} else {
457
490
fs:: copy ( entry. path ( ) , & destination)
458
491
. path_context ( entry. path ( ) , "failed to copy file" ) ?;
0 commit comments