@@ -19,13 +19,12 @@ use std::env;
19
19
use std:: ffi:: { OsStr , OsString } ;
20
20
use std:: fs:: { self , File } ;
21
21
use std:: io:: Write ;
22
- use std:: path:: { Path , PathBuf } ;
22
+ use std:: path:: PathBuf ;
23
23
use std:: sync:: Arc ;
24
24
25
25
use failure:: Error ;
26
26
use lazycell:: LazyCell ;
27
27
use log:: debug;
28
- use same_file:: is_same_file;
29
28
use serde:: Serialize ;
30
29
31
30
pub use self :: build_config:: { BuildConfig , CompileMode , MessageFormat } ;
@@ -443,12 +442,12 @@ fn link_targets<'a, 'cfg>(
443
442
}
444
443
} ;
445
444
destinations. push ( dst. clone ( ) ) ;
446
- hardlink_or_copy ( src, dst) ?;
445
+ paths :: link_or_copy ( src, dst) ?;
447
446
if let Some ( ref path) = output. export_path {
448
447
let export_dir = export_dir. as_ref ( ) . unwrap ( ) ;
449
448
paths:: create_dir_all ( export_dir) ?;
450
449
451
- hardlink_or_copy ( src, path) ?;
450
+ paths :: link_or_copy ( src, path) ?;
452
451
}
453
452
}
454
453
@@ -477,54 +476,6 @@ fn link_targets<'a, 'cfg>(
477
476
} ) )
478
477
}
479
478
480
- /// Hardlink (file) or symlink (dir) src to dst if possible, otherwise copy it.
481
- fn hardlink_or_copy ( src : & Path , dst : & Path ) -> CargoResult < ( ) > {
482
- debug ! ( "linking {} to {}" , src. display( ) , dst. display( ) ) ;
483
- if is_same_file ( src, dst) . unwrap_or ( false ) {
484
- return Ok ( ( ) ) ;
485
- }
486
-
487
- // NB: we can't use dst.exists(), as if dst is a broken symlink,
488
- // dst.exists() will return false. This is problematic, as we still need to
489
- // unlink dst in this case. symlink_metadata(dst).is_ok() will tell us
490
- // whether dst exists *without* following symlinks, which is what we want.
491
- if fs:: symlink_metadata ( dst) . is_ok ( ) {
492
- paths:: remove_file ( & dst) ?;
493
- }
494
-
495
- let link_result = if src. is_dir ( ) {
496
- #[ cfg( target_os = "redox" ) ]
497
- use std:: os:: redox:: fs:: symlink;
498
- #[ cfg( unix) ]
499
- use std:: os:: unix:: fs:: symlink;
500
- #[ cfg( windows) ]
501
- use std:: os:: windows:: fs:: symlink_dir as symlink;
502
-
503
- let dst_dir = dst. parent ( ) . unwrap ( ) ;
504
- let src = if src. starts_with ( dst_dir) {
505
- src. strip_prefix ( dst_dir) . unwrap ( )
506
- } else {
507
- src
508
- } ;
509
- symlink ( src, dst)
510
- } else {
511
- fs:: hard_link ( src, dst)
512
- } ;
513
- link_result
514
- . or_else ( |err| {
515
- debug ! ( "link failed {}. falling back to fs::copy" , err) ;
516
- fs:: copy ( src, dst) . map ( |_| ( ) )
517
- } )
518
- . chain_err ( || {
519
- format ! (
520
- "failed to link or copy `{}` to `{}`" ,
521
- src. display( ) ,
522
- dst. display( )
523
- )
524
- } ) ?;
525
- Ok ( ( ) )
526
- }
527
-
528
479
// For all plugin dependencies, add their -L paths (now calculated and present
529
480
// in `build_script_outputs`) to the dynamic library load path for the command
530
481
// to execute.
0 commit comments