Skip to content

Commit

Permalink
Merge pull request #2274 from lzutao/escape-nt-backslash
Browse files Browse the repository at this point in the history
Escape Windows backslash when outputing to markdown
  • Loading branch information
kinnison committed Apr 16, 2020
2 parents 93e6d7d + cac1d3a commit 2138b7a
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use rustup::utils::Notification;
use rustup::{Cfg, UpdateStatus};
use rustup::{DUP_TOOLS, TOOLS};
use same_file::Handle;
use std::borrow::Cow;
use std::env;
use std::env::consts::EXE_SUFFIX;
use std::fs;
Expand All @@ -65,7 +66,7 @@ pub const NEVER_SELF_UPDATE: bool = false;
// argument of format! needs to be a literal.

macro_rules! pre_install_msg_template {
($platform_msg: expr) => {
($platform_msg:literal) => {
concat!(
r"
# Welcome to Rust!
Expand Down Expand Up @@ -215,22 +216,21 @@ static UPDATE_ROOT: &str = "https://static.rust-lang.org/rustup";

/// `CARGO_HOME` suitable for display, possibly with $HOME
/// substituted for the directory prefix
fn canonical_cargo_home() -> Result<String> {
fn canonical_cargo_home() -> Result<Cow<'static, str>> {
let path = utils::cargo_home()?;
let mut path_str = path.to_string_lossy().into_owned();

let default_cargo_home = utils::home_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join(".cargo");
if default_cargo_home == path {
Ok(if default_cargo_home == path {
if cfg!(unix) {
path_str = String::from("$HOME/.cargo");
"$HOME/.cargo".into()
} else {
path_str = String::from(r"%USERPROFILE%\.cargo");
r"%USERPROFILE%\.cargo".into()
}
}

Ok(path_str)
} else {
path.to_string_lossy().into_owned().into()
})
}

/// Installing is a simple matter of copying the running binary to
Expand Down Expand Up @@ -327,22 +327,19 @@ pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpt
}

let cargo_home = canonical_cargo_home()?;
let msg = if !opts.no_modify_path {
if cfg!(unix) {
format!(post_install_msg_unix!(), cargo_home = cargo_home)
} else {
format!(post_install_msg_win!(), cargo_home = cargo_home)
}
} else if cfg!(unix) {
format!(
#[cfg(windows)]
let cargo_home = cargo_home.replace('\\', r"\\");
let msg = match (opts.no_modify_path, cfg!(unix)) {
(false, true) => format!(post_install_msg_unix!(), cargo_home = cargo_home),
(false, false) => format!(post_install_msg_win!(), cargo_home = cargo_home),
(true, true) => format!(
post_install_msg_unix_no_modify_path!(),
cargo_home = cargo_home
)
} else {
format!(
),
(true, false) => format!(
post_install_msg_win_no_modify_path!(),
cargo_home = cargo_home
)
),
};
md(&mut term, msg);

Expand Down

0 comments on commit 2138b7a

Please sign in to comment.