@@ -8,6 +8,7 @@ use lazy_static::lazy_static;
88use rustup:: utils:: notify:: NotificationLevel ;
99use rustup:: utils:: utils;
1010use rustup:: { Cfg , Notification , Toolchain , UpdateStatus } ;
11+ use std:: fs;
1112use std:: io:: { BufRead , BufReader , ErrorKind , Write } ;
1213use std:: path:: Path ;
1314use std:: process:: { Command , Stdio } ;
@@ -424,14 +425,28 @@ pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<()> {
424425 Ok ( ( ) )
425426}
426427
427- pub fn list_toolchains ( cfg : & Cfg , is_verbose : bool ) -> Result < ( ) > {
428- let toolchains = cfg. list_toolchains ( ) ?;
429- let toolchain_info = if is_verbose {
430- format ! ( "\t {}" , & cfg. rustup_dir. display( ) )
428+ fn print_toolchain_path ( cfg : & Cfg , toolchain : & str , if_default : & str , verbose : bool ) -> Result < ( ) > {
429+ let toolchain_path = {
430+ let mut t_path = cfg. toolchains_dir . clone ( ) ;
431+ t_path. push ( & toolchain) ;
432+ t_path
433+ } ;
434+ let toolchain_meta = fs:: symlink_metadata ( & toolchain_path) ?;
435+ let toolchain_path = if verbose {
436+ if toolchain_meta. is_dir ( ) {
437+ format ! ( "\t {}" , toolchain_path. display( ) )
438+ } else {
439+ format ! ( "\t {}" , fs:: read_link( toolchain_path) ?. display( ) )
440+ }
431441 } else {
432- String :: from ( "" )
442+ String :: new ( )
433443 } ;
444+ println ! ( "{}{}{}" , & toolchain, if_default, toolchain_path) ;
445+ Ok ( ( ) )
446+ }
434447
448+ pub fn list_toolchains ( cfg : & Cfg , verbose : bool ) -> Result < ( ) > {
449+ let toolchains = cfg. list_toolchains ( ) ?;
435450 if toolchains. is_empty ( ) {
436451 println ! ( "no installed toolchains" ) ;
437452 } else if let Ok ( Some ( def_toolchain) ) = cfg. find_default ( ) {
@@ -441,11 +456,13 @@ pub fn list_toolchains(cfg: &Cfg, is_verbose: bool) -> Result<()> {
441456 } else {
442457 ""
443458 } ;
444- println ! ( "{}{}{}" , & toolchain, if_default, toolchain_info) ;
459+ print_toolchain_path ( cfg, & toolchain, if_default, verbose)
460+ . expect ( "Failed to list toolchains' directories" ) ;
445461 }
446462 } else {
447463 for toolchain in toolchains {
448- println ! ( "{}{}" , & toolchain, toolchain_info) ;
464+ print_toolchain_path ( cfg, & toolchain, "" , verbose)
465+ . expect ( "Failed to list toolchains' directories" ) ;
449466 }
450467 }
451468 Ok ( ( ) )
0 commit comments