Skip to content

Commit

Permalink
rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Apr 17, 2019
1 parent 04b654d commit ebde0f9
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 23 deletions.
1 change: 0 additions & 1 deletion download/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ pub mod reqwest_be {
callback: &dyn Fn(Event<'_>) -> Result<()>,
) -> Result<bool> {
use std::fs;
use std::io;

// The file scheme is mostly for use by tests to mock the dist server
if url.scheme() == "file" {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ pub fn cli() -> App<'static, 'static> {
.map(|&shell| ("shell", Some(shell), "rustup"))
.collect::<Vec<_>>();

app.subcommand(
app
.subcommand(
SubCommand::with_name("set")
.about("Alter rustup settings")
Expand Down
1 change: 0 additions & 1 deletion src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts) -> Result<()> {
fn do_anti_sudo_check(no_prompt: bool) -> Result<()> {
#[cfg(unix)]
pub fn home_mismatch() -> bool {
use std::env;
use std::ffi::CStr;
use std::mem;
use std::ops::Deref;
Expand Down
1 change: 0 additions & 1 deletion src/dist/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ fn update_from_dist_<'a>(
force_update,
&download,
&download.notify_handler,
&toolchain.manifest_name(),
)? {
UpdateStatus::Unchanged => Ok(None),
UpdateStatus::Changed => Ok(Some(hash)),
Expand Down
2 changes: 1 addition & 1 deletion src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use crate::errors::*;
use crate::utils::toml_utils::*;

use crate::dist::{Profile, TargetTriple};
use crate::dist::dist::{Profile, TargetTriple};
use std::collections::HashMap;

pub const SUPPORTED_MANIFEST_VERSIONS: [&str; 1] = ["2"];
Expand Down
19 changes: 8 additions & 11 deletions src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Changes {
.chain(self.explicit_add_components.iter())
}

fn check_invariants(&self, rust_target_package: &TargetedPackage, config: &Option<Config>) {
fn check_invariants(&self, config: &Option<Config>) {
for component_to_add in self.iter_add_components() {
assert!(
!self.remove_components.contains(component_to_add),
Expand Down Expand Up @@ -111,7 +111,6 @@ impl Manifestation {
force_update: bool,
download_cfg: &DownloadCfg<'_>,
notify_handler: &dyn Fn(Notification<'_>),
toolchain_str: &str,
) -> Result<UpdateStatus> {
// Some vars we're going to need a few times
let temp_cfg = download_cfg.temp_cfg;
Expand All @@ -121,7 +120,7 @@ impl Manifestation {

// Create the lists of components needed for installation
let config = self.read_config()?;
let update = Update::build_update(self, new_manifest, &changes, config, notify_handler)?;
let update = Update::build_update(self, new_manifest, &changes, &config, notify_handler)?;

if update.nothing_changes() {
// TODO chnages and ,manifest are empty?
Expand All @@ -130,7 +129,7 @@ impl Manifestation {
}

// Validate that the requested components are available
match update.unavailable_components(new_manifest, toolchain_str) {
match update.unavailable_components(new_manifest) {
Ok(_) => {}
_ if force_update => {}
Err(e) => return Err(e),
Expand Down Expand Up @@ -471,15 +470,15 @@ impl Update {
fn build_update(
manifestation: &Manifestation,
new_manifest: &Manifest,
changes: Changes,
notify_handler: &dyn Fn(Notification<'_>),
changes: &Changes,
config: &Option<Config>,
notify_handler: &dyn Fn(Notification<'_>),
) -> Result<Update> {
// The package to install.
let rust_package = new_manifest.get_package("rust")?;
let rust_target_package = rust_package.get_target(Some(&manifestation.target_triple))?;

changes.check_invariants(rust_target_package, &config);
changes.check_invariants(&config);

// The list of components already installed, empty if a new install
let starting_list = config
Expand All @@ -501,7 +500,7 @@ impl Update {
&starting_list,
rust_target_package,
new_manifest,
changes,
&changes,
config,
);

Expand All @@ -527,7 +526,7 @@ impl Update {
for component in &result.final_component_list {
if !starting_list.contains(component) {
result.components_to_install.push(component.clone());
} else if changes.add_extensions.contains(&component) {
} else if changes.explicit_add_components.contains(&component) {
notify_handler(Notification::ComponentAlreadyInstalled(
&component.description(new_manifest),
));
Expand All @@ -548,7 +547,6 @@ impl Update {
rust_target_package: &TargetedPackage,
new_manifest: &Manifest,
changes: &Changes,
notify_handler: &dyn Fn(Notification<'_>),
config: &Option<Config>,
) {
// Add requested components
Expand Down Expand Up @@ -622,7 +620,6 @@ impl Update {
return Err(ErrorKind::RequestedComponentsUnavailable(
unavailable_components,
new_manifest.clone(),
toolchain_str.to_owned(),
)
.into());
}
Expand Down
45 changes: 42 additions & 3 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::component_for_bin;
use crate::dist::manifest::{Component, Manifest};
use crate::dist::temp;
use crate::dist::dist::Profile;
use error_chain::error_chain;
use error_chain::error_chain_processing;
use error_chain::{impl_error_chain_kind, impl_error_chain_processed, impl_extract_backtrace};
Expand Down Expand Up @@ -270,9 +271,9 @@ error_chain! {
description("missing package for the target of a rename")
display("server sent a broken manifest: missing package for the target of a rename {}", name)
}
RequestedComponentsUnavailable(c: Vec<Component>, manifest: Manifest, toolchain: String) {
RequestedComponentsUnavailable(c: Vec<Component>, manifest: Manifest) {
description("some requested components are unavailable to download")
display("{} for channel '{}'", component_unavailable_msg(&c, &manifest), toolchain)
display("{}", component_unavailable_msg(&c, &manifest))
}
UnknownMetadataVersion(v: String) {
description("unknown metadata version")
Expand Down Expand Up @@ -313,7 +314,7 @@ error_chain! {
display(
"unknown profile name: '{}'; valid profile names are {}",
p,
dist::Profile::names()
Profile::names()
.iter()
.map(|s| format!("'{}'", s))
.collect::<Vec<_>>()
Expand Down Expand Up @@ -346,3 +347,41 @@ fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
None => String::new(),
}
}

fn component_unavailable_msg(cs: &[Component], manifest: &Manifest) -> String {
assert!(!cs.is_empty());

let mut buf = vec![];

if cs.len() == 1 {
let _ = write!(
buf,
"component {} is unavailable for download",
&cs[0].description(manifest)
);
} else {
use itertools::Itertools;
let same_target = cs
.iter()
.all(|c| c.target == cs[0].target || c.target.is_none());
if same_target {
let mut cs_strs = cs.iter().map(|c| format!("'{}'", c.short_name(manifest)));
let cs_str = cs_strs.join(", ");
let _ = write!(
buf,
"some components unavailable for download: {}\n{}",
cs_str, TOOLSTATE_MSG,
);
} else {
let mut cs_strs = cs.iter().map(|c| c.description(manifest));
let cs_str = cs_strs.join(", ");
let _ = write!(
buf,
"some components unavailable for download: {}\n{}",
cs_str, TOOLSTATE_MSG,
);
}
}

String::from_utf8(buf).expect("")
}
4 changes: 1 addition & 3 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ impl<'a> Toolchain<'a> {
false,
&self.download_cfg(),
&self.download_cfg().notify_handler,
&toolchain.manifest_name(),
)?;
)?;

Ok(())
} else {
Expand Down Expand Up @@ -607,7 +606,6 @@ impl<'a> Toolchain<'a> {
false,
&self.download_cfg(),
&self.download_cfg().notify_handler,
&toolchain.manifest_name(),
)?;

Ok(())
Expand Down
1 change: 0 additions & 1 deletion src/utils/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ pub fn find_cmd<'a>(cmds: &[&'a str]) -> Option<&'a str> {
pub fn open_browser(path: &Path) -> io::Result<bool> {
#[cfg(not(windows))]
fn inner(path: &Path) -> io::Result<bool> {
use std::env;
use std::process::Stdio;

let env_browser = env::var_os("BROWSER").map(|b| env::split_paths(&b).collect::<Vec<_>>());
Expand Down

0 comments on commit ebde0f9

Please sign in to comment.