From b459a9230cf6a7c561312e93a333abc5f7bc11ba Mon Sep 17 00:00:00 2001 From: Jan David Date: Mon, 27 Mar 2023 17:12:42 +0200 Subject: [PATCH 01/10] Add preload directive to HSTS header The preload directive has been added to the Strict-Transport-Security header to enable HSTS preloading. --- www/website_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/website_config.json b/www/website_config.json index 77a7a4908d..af99e0ec8d 100644 --- a/www/website_config.json +++ b/www/website_config.json @@ -1,6 +1,6 @@ { "headers": { - "Strict-Transport-Security": "max-age=63072000; includeSubDomains", + "Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload", "X-Content-Type-Options": "nosniff", "X-Frame-Options": "DENY", "X-XSS-Protection": "1; mode=block", From 47f4b853b0dc982400d92c0c819247deb314b4bd Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 28 Mar 2023 01:01:21 +0700 Subject: [PATCH 02/10] Set SubcommandRequiredElseHelp correctly Signed-off-by: hi-rustin --- src/cli/rustup_mode.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index b63678e29e..12cdf6d650 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -226,7 +226,7 @@ pub(crate) fn cli() -> Command<'static> { .about("The Rust toolchain installer") .after_help(RUSTUP_HELP) .global_setting(AppSettings::DeriveDisplayOrder) - .arg_required_else_help(true) + .setting(AppSettings::SubcommandRequiredElseHelp) .arg( verbose_arg("Enable verbose output"), ) @@ -369,8 +369,7 @@ pub(crate) fn cli() -> Command<'static> { Command::new("toolchain") .about("Modify or query the installed toolchains") .after_help(TOOLCHAIN_HELP) - .subcommand_required(true) - .arg_required_else_help(true) + .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( Command::new("list") .about("List installed toolchains") @@ -475,8 +474,7 @@ pub(crate) fn cli() -> Command<'static> { .subcommand( Command::new("target") .about("Modify a toolchain's supported targets") - .subcommand_required(true) - .arg_required_else_help(true) + .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( Command::new("list") .about("List installed and available targets") @@ -536,8 +534,7 @@ pub(crate) fn cli() -> Command<'static> { .subcommand( Command::new("component") .about("Modify a toolchain's installed components") - .subcommand_required(true) - .arg_required_else_help(true) + .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( Command::new("list") .about("List installed and available components") @@ -593,8 +590,7 @@ pub(crate) fn cli() -> Command<'static> { Command::new("override") .about("Modify directory toolchain overrides") .after_help(OVERRIDE_HELP) - .subcommand_required(true) - .arg_required_else_help(true) + .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( Command::new("list").about("List directory toolchain overrides"), ) @@ -722,8 +718,7 @@ pub(crate) fn cli() -> Command<'static> { .subcommand( Command::new("self") .about("Modify the rustup installation") - .subcommand_required(true) - .arg_required_else_help(true) + .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand(Command::new("update").about("Download and install updates to rustup")) .subcommand( Command::new("uninstall") @@ -737,8 +732,7 @@ pub(crate) fn cli() -> Command<'static> { .subcommand( Command::new("set") .about("Alter rustup settings") - .subcommand_required(true) - .arg_required_else_help(true) + .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( Command::new("default-host") .about("The triple used to identify toolchains when not specified") From 81fad9d0f15241efda607ec50ac5a24ca928fcfa Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 28 Mar 2023 10:00:52 +0700 Subject: [PATCH 03/10] Update UI tests Signed-off-by: hi-rustin --- tests/suite/cli-ui/rustup/rustup_help_cmd_stdout.toml | 2 +- tests/suite/cli-ui/rustup/rustup_help_flag_stdout.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suite/cli-ui/rustup/rustup_help_cmd_stdout.toml b/tests/suite/cli-ui/rustup/rustup_help_cmd_stdout.toml index 65d9e2b2d5..68caeb20d7 100644 --- a/tests/suite/cli-ui/rustup/rustup_help_cmd_stdout.toml +++ b/tests/suite/cli-ui/rustup/rustup_help_cmd_stdout.toml @@ -6,7 +6,7 @@ rustup [..] The Rust toolchain installer USAGE: - rustup[EXE] [OPTIONS] [+toolchain] [SUBCOMMAND] + rustup[EXE] [OPTIONS] [+toolchain] ARGS: <+toolchain> release channel (e.g. +stable) or custom toolchain to set override diff --git a/tests/suite/cli-ui/rustup/rustup_help_flag_stdout.toml b/tests/suite/cli-ui/rustup/rustup_help_flag_stdout.toml index 03c6963a35..c0f051e22a 100644 --- a/tests/suite/cli-ui/rustup/rustup_help_flag_stdout.toml +++ b/tests/suite/cli-ui/rustup/rustup_help_flag_stdout.toml @@ -6,7 +6,7 @@ rustup [..] The Rust toolchain installer USAGE: - rustup[EXE] [OPTIONS] [+toolchain] [SUBCOMMAND] + rustup[EXE] [OPTIONS] [+toolchain] ARGS: <+toolchain> release channel (e.g. +stable) or custom toolchain to set override From ee000fe82a623b70126a3f65929e6ce0efbe34c5 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 28 Mar 2023 11:08:23 +0700 Subject: [PATCH 04/10] Add a test for only options command Signed-off-by: hi-rustin --- .../rustup/rustup_only_options_stdout.toml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/suite/cli-ui/rustup/rustup_only_options_stdout.toml diff --git a/tests/suite/cli-ui/rustup/rustup_only_options_stdout.toml b/tests/suite/cli-ui/rustup/rustup_only_options_stdout.toml new file mode 100644 index 0000000000..e7d2600424 --- /dev/null +++ b/tests/suite/cli-ui/rustup/rustup_only_options_stdout.toml @@ -0,0 +1,48 @@ +bin.name = "rustup" +args = ["-v"] +status.code = 1 +stdout = """ +rustup [..] +The Rust toolchain installer + +USAGE: + rustup[EXE] [OPTIONS] [+toolchain] + +ARGS: + <+toolchain> release channel (e.g. +stable) or custom toolchain to set override + +OPTIONS: + -v, --verbose Enable verbose output + -q, --quiet Disable progress output + -h, --help Print help information + -V, --version Print version information + +SUBCOMMANDS: + show Show the active and installed toolchains or profiles + update Update Rust toolchains and rustup + check Check for updates to Rust toolchains and rustup + default Set the default toolchain + toolchain Modify or query the installed toolchains + target Modify a toolchain's supported targets + component Modify a toolchain's installed components + override Modify directory toolchain overrides + run Run a command with an environment configured for a given toolchain + which Display which binary will be run for a given command + doc Open the documentation for the current toolchain +... + self Modify the rustup installation + set Alter rustup settings + completions Generate tab-completion scripts for your shell + help Print this message or the help of the given subcommand(s) + +DISCUSSION: + Rustup installs The Rust Programming Language from the official + release channels, enabling you to easily switch between stable, + beta, and nightly compilers and keep them updated. It makes + cross-compiling simpler with binary builds of the standard library + for common platforms. + + If you are new to Rust consider running `rustup doc --book` to + learn Rust. +""" +stderr = "" From a9589c7295ebc28972482f8a715cbdd9a0173d53 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 28 Mar 2023 12:04:50 -0400 Subject: [PATCH 05/10] Fix RUSTUP_PERMIT_COPY_RENAME condition so it is actually used The addition of the experimental io::ErrorKind::CrossesDevices variant prevented the RUSTUP_PERMIT_COPY_RENAME condition on io::ErrorKind::Other from matching. This shows why it is a bad idea to explicitly match on io::ErrorKind::Other rather than using the default pattern and it doesn't seem like there was any need to do that anyways given the raw_os_error condition. --- src/utils/utils.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/utils/utils.rs b/src/utils/utils.rs index 2db3368bef..3a58ce4abf 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -622,9 +622,8 @@ where OperationResult::Retry(e) } #[cfg(target_os = "linux")] - io::ErrorKind::Other - if process().var_os("RUSTUP_PERMIT_COPY_RENAME").is_some() - && Some(EXDEV) == e.raw_os_error() => + _ if process().var_os("RUSTUP_PERMIT_COPY_RENAME").is_some() + && Some(EXDEV) == e.raw_os_error() => { match copy_and_delete(name, src, dest, notify_handler) { Ok(()) => OperationResult::Ok(()), From 12f3f4143b90da6ff1834a11fbef41abf77675c7 Mon Sep 17 00:00:00 2001 From: Aurora <68289086+aurora1691@users.noreply.github.com> Date: Wed, 29 Mar 2023 20:47:18 +0000 Subject: [PATCH 06/10] Update network-proxies.md --- doc/src/network-proxies.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/network-proxies.md b/doc/src/network-proxies.md index dead171aa4..19a42090b8 100644 --- a/doc/src/network-proxies.md +++ b/doc/src/network-proxies.md @@ -38,6 +38,6 @@ http_proxy=proxy.example.com:1080` (and likewise for HTTPS). If you are getting an SSL `unknown protocol` error from `rustup` via `libcurl` but the command-line `curl` command works fine, this may be the problem. -[curlman]: https://curl.haxx.se/docs/manpage.html +[curlman]: https://curl.se/docs/manpage.html#:~:text=Environment,-The%20environment%20variables [cmd]: https://en.wikipedia.org/wiki/Cmd.exe [ps]: https://en.wikipedia.org/wiki/PowerShell From 352ad97bb96270038f1c871f8e2143dce9319bb4 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 1 Apr 2023 23:25:31 +0700 Subject: [PATCH 07/10] Revert `Update Rust crate term to v0.7.0` Signed-off-by: hi-rustin --- Cargo.lock | 51 +++++++++------------------------------------------ Cargo.toml | 2 +- 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5c46658670..4e915c165f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -119,6 +119,12 @@ version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "bytes" version = "1.4.0" @@ -411,27 +417,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if 1.0.0", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "download" version = "1.25.2" @@ -1358,17 +1343,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "redox_users" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" -dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", -] - [[package]] name = "regex" version = "1.7.1" @@ -1586,12 +1560,6 @@ dependencies = [ "zstd", ] -[[package]] -name = "rustversion" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" - [[package]] name = "ryu" version = "1.0.12" @@ -1880,12 +1848,11 @@ dependencies = [ [[package]] name = "term" -version = "0.7.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +checksum = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561" dependencies = [ - "dirs-next", - "rustversion", + "byteorder", "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 4d985a0ab9..77e0d5b1cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ strsim = "0.10" tar = "0.4.26" tempfile.workspace = true # FIXME(issue #1818, #1826, and friends) -term = "=0.7.0" +term = "=0.5.1" thiserror.workspace = true threadpool = "1" toml = "0.5" From b579e23a7503f7943fd80c7d5a1da67a8aebfa22 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 4 Apr 2023 10:56:08 +0800 Subject: [PATCH 08/10] Print help when a ValueValidation error occurs Signed-off-by: hi-rustin --- src/cli/rustup_mode.rs | 15 +++++- .../rustup/rustup_unknown_arg_stdout.toml | 51 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 12cdf6d650..10bfc8475f 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -30,6 +30,10 @@ use crate::utils::utils; use crate::Notification; use crate::{command, Cfg, ComponentStatus, Toolchain}; +const TOOLCHAIN_OVERRIDE_ERROR: &str = + "To override the toolchain using the 'rustup +toolchain' syntax, \ + make sure to prefix the toolchain override with a '+'"; + fn handle_epipe(res: Result) -> Result { match res { Err(e) => { @@ -110,6 +114,15 @@ pub fn main() -> Result { write!(process().stdout().lock(), "{err}")?; return Ok(utils::ExitCode(1)); } + if err.kind() == ValueValidation { + if err.to_string().contains(TOOLCHAIN_OVERRIDE_ERROR) { + err!("{TOOLCHAIN_OVERRIDE_ERROR}\n"); + cli().print_help()?; + } else { + write!(process().stdout().lock(), "{err}")?; + } + return Ok(utils::ExitCode(1)); + } Err(err) } }?; @@ -245,7 +258,7 @@ pub(crate) fn cli() -> Command<'static> { if s.starts_with('+') { Ok(s.to_owned()) } else { - Err("Toolchain overrides must begin with '+'".to_owned()) + Err(TOOLCHAIN_OVERRIDE_ERROR.to_owned()) } }), ) diff --git a/tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml b/tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml new file mode 100644 index 0000000000..7d865cc55d --- /dev/null +++ b/tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml @@ -0,0 +1,51 @@ +bin.name = "rustup" +args = ["random"] +status.code = 1 +stdout = """ +rustup [..] +The Rust toolchain installer + +USAGE: + rustup[EXE] [OPTIONS] [+toolchain] + +ARGS: + <+toolchain> release channel (e.g. +stable) or custom toolchain to set override + +OPTIONS: + -v, --verbose Enable verbose output + -q, --quiet Disable progress output + -h, --help Print help information + -V, --version Print version information + +SUBCOMMANDS: + show Show the active and installed toolchains or profiles + update Update Rust toolchains and rustup + check Check for updates to Rust toolchains and rustup + default Set the default toolchain + toolchain Modify or query the installed toolchains + target Modify a toolchain's supported targets + component Modify a toolchain's installed components + override Modify directory toolchain overrides + run Run a command with an environment configured for a given toolchain + which Display which binary will be run for a given command + doc Open the documentation for the current toolchain +... + self Modify the rustup installation + set Alter rustup settings + completions Generate tab-completion scripts for your shell + help Print this message or the help of the given subcommand(s) + +DISCUSSION: + Rustup installs The Rust Programming Language from the official + release channels, enabling you to easily switch between stable, + beta, and nightly compilers and keep them updated. It makes + cross-compiling simpler with binary builds of the standard library + for common platforms. + + If you are new to Rust consider running `rustup doc --book` to + learn Rust. +""" +stderr = """ +error: To override the toolchain using the 'rustup +toolchain' syntax, make sure to prefix the toolchain override with a '+' + +""" From a6a858783be1ad8938d98d151dade8d7c4cab36c Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 4 Apr 2023 23:57:19 +0800 Subject: [PATCH 09/10] Better error instead of show the help Signed-off-by: hi-rustin --- src/cli/rustup_mode.rs | 13 ++--- .../rustup/rustup_unknown_arg_stdout.toml | 48 ++----------------- tests/suite/cli_misc.rs | 5 +- 3 files changed, 12 insertions(+), 54 deletions(-) diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 10bfc8475f..09d137965d 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -114,13 +114,8 @@ pub fn main() -> Result { write!(process().stdout().lock(), "{err}")?; return Ok(utils::ExitCode(1)); } - if err.kind() == ValueValidation { - if err.to_string().contains(TOOLCHAIN_OVERRIDE_ERROR) { - err!("{TOOLCHAIN_OVERRIDE_ERROR}\n"); - cli().print_help()?; - } else { - write!(process().stdout().lock(), "{err}")?; - } + if err.kind() == ValueValidation && err.to_string().contains(TOOLCHAIN_OVERRIDE_ERROR) { + write!(process().stderr().lock(), "{err}")?; return Ok(utils::ExitCode(1)); } Err(err) @@ -258,7 +253,9 @@ pub(crate) fn cli() -> Command<'static> { if s.starts_with('+') { Ok(s.to_owned()) } else { - Err(TOOLCHAIN_OVERRIDE_ERROR.to_owned()) + Err(format!( + "\"{s}\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. {TOOLCHAIN_OVERRIDE_ERROR}" + )) } }), ) diff --git a/tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml b/tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml index 7d865cc55d..7508714f03 100644 --- a/tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml +++ b/tests/suite/cli-ui/rustup/rustup_unknown_arg_stdout.toml @@ -1,51 +1,9 @@ bin.name = "rustup" args = ["random"] status.code = 1 -stdout = """ -rustup [..] -The Rust toolchain installer - -USAGE: - rustup[EXE] [OPTIONS] [+toolchain] - -ARGS: - <+toolchain> release channel (e.g. +stable) or custom toolchain to set override - -OPTIONS: - -v, --verbose Enable verbose output - -q, --quiet Disable progress output - -h, --help Print help information - -V, --version Print version information - -SUBCOMMANDS: - show Show the active and installed toolchains or profiles - update Update Rust toolchains and rustup - check Check for updates to Rust toolchains and rustup - default Set the default toolchain - toolchain Modify or query the installed toolchains - target Modify a toolchain's supported targets - component Modify a toolchain's installed components - override Modify directory toolchain overrides - run Run a command with an environment configured for a given toolchain - which Display which binary will be run for a given command - doc Open the documentation for the current toolchain -... - self Modify the rustup installation - set Alter rustup settings - completions Generate tab-completion scripts for your shell - help Print this message or the help of the given subcommand(s) - -DISCUSSION: - Rustup installs The Rust Programming Language from the official - release channels, enabling you to easily switch between stable, - beta, and nightly compilers and keep them updated. It makes - cross-compiling simpler with binary builds of the standard library - for common platforms. - - If you are new to Rust consider running `rustup doc --book` to - learn Rust. -""" +stdout = "" stderr = """ -error: To override the toolchain using the 'rustup +toolchain' syntax, make sure to prefix the toolchain override with a '+' +error: Invalid value \"random\" for '<+toolchain>': \"random\" is not a valid subcommand, so it was interpreted as a toolchain name, but it is also invalid. To override the toolchain using the 'rustup +toolchain' syntax, make sure to prefix the toolchain override with a '+' +For more information try --help """ diff --git a/tests/suite/cli_misc.rs b/tests/suite/cli_misc.rs index 1849ffc3d2..2c0f9e6902 100644 --- a/tests/suite/cli_misc.rs +++ b/tests/suite/cli_misc.rs @@ -946,7 +946,10 @@ fn override_by_toolchain_on_the_command_line() { ); config.expect_err( &["rustup", "@stable", "which", "rustc"], - r#"Invalid value "@stable" for '<+toolchain>': Toolchain overrides must begin with '+'"#, + "Invalid value \"@stable\" for '<+toolchain>': \"@stable\" is not a valid subcommand, \ + so it was interpreted as a toolchain name, but it is also invalid. \ + To override the toolchain using the 'rustup +toolchain' syntax, \ + make sure to prefix the toolchain override with a '+'", ); config.expect_stderr_ok( &["rustup", "+stable", "set", "profile", "minimal"], From 4e6bda3a62ff9ed2f32dfd6d2f77ef5a1ac7005e Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 5 Apr 2023 10:24:30 +0800 Subject: [PATCH 10/10] Remove test Signed-off-by: hi-rustin --- tests/suite/cli_misc.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/suite/cli_misc.rs b/tests/suite/cli_misc.rs index 2c0f9e6902..b793b2ebfe 100644 --- a/tests/suite/cli_misc.rs +++ b/tests/suite/cli_misc.rs @@ -944,13 +944,6 @@ fn override_by_toolchain_on_the_command_line() { &["rustup", "+foo", "which", "rustc"], "toolchain 'foo' is not installed", ); - config.expect_err( - &["rustup", "@stable", "which", "rustc"], - "Invalid value \"@stable\" for '<+toolchain>': \"@stable\" is not a valid subcommand, \ - so it was interpreted as a toolchain name, but it is also invalid. \ - To override the toolchain using the 'rustup +toolchain' syntax, \ - make sure to prefix the toolchain override with a '+'", - ); config.expect_stderr_ok( &["rustup", "+stable", "set", "profile", "minimal"], "profile set to 'minimal'",