From 7e701b100d7cc005e557ec2ef920f109ceb9b56c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 8 Apr 2017 00:31:17 +0000 Subject: [PATCH] Don't crash if modifying multiple profile files --- src/rustup-cli/self_update.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 2a6c998ebb..fc137e3090 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -86,9 +86,9 @@ macro_rules! pre_install_msg_unix { () => { pre_install_msg_template!( "This path will then be added to your `PATH` environment variable by -modifying the profile file located at: +modifying the profile file{plural} located at: - {rcfiles}" +{rcfiles}" )}; } @@ -492,10 +492,13 @@ fn pre_install_msg(no_modify_path: bool) -> Result { None } }).collect::>(); - assert_eq!(rcfiles.len(), 1); // Only modifying .profile + let plural = if rcfiles.len() > 1 { "s" } else { "" }; + let rcfiles = rcfiles.into_iter().map(|f| format!(" {}", f)).collect::>(); + let rcfiles = rcfiles.join("\n"); Ok(format!(pre_install_msg_unix!(), cargo_home_bin = cargo_home_bin.display(), - rcfiles = rcfiles[0])) + plural = plural, + rcfiles = rcfiles)) } else { Ok(format!(pre_install_msg_win!(), cargo_home_bin = cargo_home_bin.display()))