@@ -184,14 +184,19 @@ Studio 2013 and during install select the "C++ tools":
184
184
185
185
_Install the C++ build tools before proceeding_.
186
186
187
- If you will be targetting the GNU ABI or otherwise know what you are
187
+ If you will be targeting the GNU ABI or otherwise know what you are
188
188
doing then it is fine to continue installation without the build
189
189
tools, but otherwise, install the C++ build tools before proceeding.
190
190
"# ;
191
191
192
192
static TOOLS : & ' static [ & ' static str ]
193
193
= & [ "rustc" , "rustdoc" , "cargo" , "rust-lldb" , "rust-gdb" , "rls" ] ;
194
194
195
+ // Tools which are commonly installed by Cargo as well as rustup. We take a bit
196
+ // more care with these to ensure we don't overwrite the user's previous
197
+ // installation.
198
+ static DUP_TOOLS : & ' static [ & ' static str ] = & [ "rustfmt" , "cargo-fmt" ] ;
199
+
195
200
static UPDATE_ROOT : & ' static str
196
201
= "https://static.rust-lang.org/rustup" ;
197
202
@@ -646,13 +651,31 @@ fn install_bins() -> Result<()> {
646
651
try!( utils:: copy_file ( this_exe_path, rustup_path) ) ;
647
652
try!( utils:: make_executable ( rustup_path) ) ;
648
653
654
+ // Record the size of the known links, then when we get files which may or
655
+ // may not be links, we compare their size. Same size means probably a link.
656
+ let mut file_size = 0 ;
657
+
649
658
// Try to hardlink all the Rust exes to the rustup exe. Some systems,
650
659
// like Android, does not support hardlinks, so we fallback to symlinks.
651
660
for tool in TOOLS {
652
661
let ref tool_path = bin_path. join ( & format ! ( "{}{}" , tool, EXE_SUFFIX ) ) ;
662
+ if tool_path. exists ( ) {
663
+ file_size = utils:: file_size ( tool_path) ?;
664
+ }
653
665
try!( utils:: hard_or_symlink_file ( rustup_path, tool_path) ) ;
654
666
}
655
667
668
+ for tool in DUP_TOOLS {
669
+ let ref tool_path = bin_path. join ( & format ! ( "{}{}" , tool, EXE_SUFFIX ) ) ;
670
+ if tool_path. exists ( ) && ( file_size == 0 || utils:: file_size ( tool_path) ? != file_size) {
671
+ warn ! ( "tool `{}` is already installed, remove it from `{}`, then run `rustup update` \
672
+ to have rustup manage this tool.",
673
+ tool, bin_path. to_string_lossy( ) ) ;
674
+ } else {
675
+ try!( utils:: hard_or_symlink_file ( rustup_path, tool_path) ) ;
676
+ }
677
+ }
678
+
656
679
Ok ( ( ) )
657
680
}
658
681
@@ -752,7 +775,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
752
775
753
776
// Then everything in bin except rustup and tools. These can't be unlinked
754
777
// until this process exits (on windows).
755
- let tools = TOOLS . iter ( ) . map ( |t| format ! ( "{}{}" , t, EXE_SUFFIX ) ) ;
778
+ let tools = TOOLS . iter ( ) . chain ( DUP_TOOLS . iter ( ) ) . map ( |t| format ! ( "{}{}" , t, EXE_SUFFIX ) ) ;
756
779
let tools: Vec < _ > = tools. chain ( vec ! [ format!( "rustup{}" , EXE_SUFFIX ) ] ) . collect ( ) ;
757
780
for dirent in try!( fs:: read_dir ( & cargo_home. join ( "bin" ) ) . chain_err ( || read_dir_err) ) {
758
781
let dirent = try!( dirent. chain_err ( || read_dir_err) ) ;
0 commit comments