@@ -184,14 +184,19 @@ Studio 2013 and during install select the "C++ tools":
184184
185185_Install the C++ build tools before proceeding_.
186186
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
188188doing then it is fine to continue installation without the build
189189tools, but otherwise, install the C++ build tools before proceeding.
190190"# ;
191191
192192static TOOLS : & ' static [ & ' static str ]
193193 = & [ "rustc" , "rustdoc" , "cargo" , "rust-lldb" , "rust-gdb" , "rls" ] ;
194194
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+
195200static UPDATE_ROOT : & ' static str
196201 = "https://static.rust-lang.org/rustup" ;
197202
@@ -646,13 +651,31 @@ fn install_bins() -> Result<()> {
646651 try!( utils:: copy_file ( this_exe_path, rustup_path) ) ;
647652 try!( utils:: make_executable ( rustup_path) ) ;
648653
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+
649658 // Try to hardlink all the Rust exes to the rustup exe. Some systems,
650659 // like Android, does not support hardlinks, so we fallback to symlinks.
651660 for tool in TOOLS {
652661 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+ }
653665 try!( utils:: hard_or_symlink_file ( rustup_path, tool_path) ) ;
654666 }
655667
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+
656679 Ok ( ( ) )
657680}
658681
@@ -752,7 +775,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
752775
753776 // Then everything in bin except rustup and tools. These can't be unlinked
754777 // 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 ) ) ;
756779 let tools: Vec < _ > = tools. chain ( vec ! [ format!( "rustup{}" , EXE_SUFFIX ) ] ) . collect ( ) ;
757780 for dirent in try!( fs:: read_dir ( & cargo_home. join ( "bin" ) ) . chain_err ( || read_dir_err) ) {
758781 let dirent = try!( dirent. chain_err ( || read_dir_err) ) ;
0 commit comments