Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use self_update;
use std::io::{Write, BufRead};
use std::process::Command;
use std::{cmp, iter};
use std::sync::Arc;
use std;
use term2;

Expand Down Expand Up @@ -101,7 +102,7 @@ pub fn set_globals(verbose: bool) -> Result<Cfg> {

let download_tracker = RefCell::new(DownloadTracker::new());

Ok(try!(Cfg::from_env(shared_ntfy!(move |n: Notification| {
Ok(try!(Cfg::from_env(Arc::new(move |n: Notification| {
if download_tracker.borrow_mut().handle_notification(&n) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/rustup-cli/multirust_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ use rustup_dist::dist::TargetTriple;
use self_update;
use std::env;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use job;

pub fn main() -> Result<()> {
try!(::self_update::cleanup_self_updater());

let need_metadata = try!(command_requires_metadata());
if need_metadata {
let cfg = try!(Cfg::from_env(shared_ntfy!(move |_: Notification| { })));
let cfg = try!(Cfg::from_env(Arc::new(move |_: Notification| { })));
try!(cfg.check_metadata_version());
}

Expand Down
18 changes: 8 additions & 10 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
//! and racy on Windows.

use common::{self, Confirm};
use rustup::{NotifyHandler};
use errors::*;
use rustup_dist::dist;
use rustup_utils::utils;
Expand Down Expand Up @@ -463,7 +462,7 @@ fn install_bins() -> Result<()> {
let ref this_exe_path = try!(utils::current_exe());
let ref multirust_path = bin_path.join(&format!("multirust{}", EXE_SUFFIX));

try!(utils::ensure_dir_exists("bin", bin_path, ntfy!(&NotifyHandler::none())));
try!(utils::ensure_dir_exists("bin", bin_path, &|_| {}));
// NB: Even on Linux we can't just copy the new binary over the (running)
// old binary; we must unlink it first.
if multirust_path.exists() {
Expand Down Expand Up @@ -528,7 +527,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
// Delete RUSTUP_HOME
let ref multirust_dir = try!(utils::multirust_home());
if multirust_dir.exists() {
try!(utils::remove_dir("multirust_home", multirust_dir, ntfy!(&NotifyHandler::none())));
try!(utils::remove_dir("multirust_home", multirust_dir, &|_| {}));
}

let read_dir_err = "failure reading directory";
Expand All @@ -546,7 +545,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
let dirent = try!(dirent.chain_err(|| read_dir_err));
if dirent.file_name().to_str() != Some("bin") {
if dirent.path().is_dir() {
try!(utils::remove_dir("cargo_home", &dirent.path(), ntfy!(&NotifyHandler::none())));
try!(utils::remove_dir("cargo_home", &dirent.path(), &|_| {}));
} else {
try!(utils::remove_file("cargo_home", &dirent.path()));
}
Expand All @@ -563,7 +562,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
let file_is_tool = name.to_str().map(|n| tools.iter().any(|t| *t == n));
if file_is_tool == Some(false) {
if dirent.path().is_dir() {
try!(utils::remove_dir("cargo_home", &dirent.path(), ntfy!(&NotifyHandler::none())));
try!(utils::remove_dir("cargo_home", &dirent.path(), &|_| {}));
} else {
try!(utils::remove_file("cargo_home", &dirent.path()));
}
Expand All @@ -585,7 +584,7 @@ pub fn uninstall(no_prompt: bool) -> Result<()> {
#[cfg(unix)]
fn delete_multirust_and_cargo_home() -> Result<()> {
let ref cargo_home = try!(utils::cargo_home());
try!(utils::remove_dir("cargo_home", cargo_home, ntfy!(&NotifyHandler::none())));
try!(utils::remove_dir("cargo_home", cargo_home, &|_| ()));

Ok(())
}
Expand Down Expand Up @@ -693,15 +692,14 @@ fn delete_multirust_and_cargo_home() -> Result<()> {
/// Run by multirust-gc-$num.exe to delete CARGO_HOME
#[cfg(windows)]
pub fn complete_windows_uninstall() -> Result<()> {
use rustup::NotifyHandler;
use std::ffi::OsStr;
use std::process::Stdio;

try!(wait_for_parent());

// Now that the parent has exited there are hopefully no more files open in CARGO_HOME
let ref cargo_home = try!(utils::cargo_home());
try!(utils::remove_dir("cargo_home", cargo_home, ntfy!(&NotifyHandler::none())));
try!(utils::remove_dir("cargo_home", cargo_home, &|_| ()));

// Now, run a *system* binary to inherit the DELETE_ON_CLOSE
// handle to *this* process, then exit. The OS will delete the gc
Expand Down Expand Up @@ -1108,7 +1106,7 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
info!("checking for self-updates");
let hash_url = try!(utils::parse_url(&(url.clone() + ".sha256")));
let hash_file = tempdir.path().join("hash");
try!(utils::download_file(&hash_url, &hash_file, None, ntfy!(&NotifyHandler::none())));
try!(utils::download_file(&hash_url, &hash_file, None, &|_| ()));
let mut latest_hash = try!(utils::read_file("hash", &hash_file));
latest_hash.truncate(64);

Expand All @@ -1127,7 +1125,7 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
try!(utils::download_file(&download_url,
&setup_path,
Some(&mut hasher),
ntfy!(&NotifyHandler::none())));
&|_| ()));
let download_hash = hasher.result_str();

// Check that hash is correct
Expand Down
1 change: 1 addition & 0 deletions src/rustup-dist/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ fn main() {
let target = env::var("TARGET").unwrap();

File::create(out_dir.join("target.txt")).unwrap().write_all(target.as_bytes()).unwrap();
println!("cargo:rerun-if-changed=build.rs");
}
1 change: 0 additions & 1 deletion src/rustup-dist/src/component/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl Components {
}
}

#[derive(Debug)]
pub struct ComponentBuilder<'a> {
components: Components,
name: String,
Expand Down
34 changes: 19 additions & 15 deletions src/rustup-dist/src/component/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! FIXME: This uses ensure_dir_exists in some places but rollback
//! does not remove any dirs created by it.

use rustup_utils::{self, utils};
use rustup_utils::utils;
use temp;
use prefix::InstallPrefix;
use errors::*;
Expand All @@ -31,19 +31,18 @@ use std::path::{Path, PathBuf};
///
/// All operations that create files will fail if the destination
/// already exists.
#[derive(Debug)]
pub struct Transaction<'a> {
prefix: InstallPrefix,
changes: Vec<ChangedItem<'a>>,
temp_cfg: &'a temp::Cfg,
notify_handler: NotifyHandler<'a>,
notify_handler: &'a Fn(Notification),
committed: bool,
}

impl<'a> Transaction<'a> {
pub fn new(prefix: InstallPrefix,
temp_cfg: &'a temp::Cfg,
notify_handler: NotifyHandler<'a>)
notify_handler: &'a Fn(Notification))
-> Self {
Transaction {
prefix: prefix,
Expand Down Expand Up @@ -131,7 +130,7 @@ impl<'a> Transaction<'a> {
pub fn temp(&self) -> &'a temp::Cfg {
self.temp_cfg
}
pub fn notify_handler(&self) -> NotifyHandler<'a> {
pub fn notify_handler(&self) -> &'a Fn(Notification) {
self.notify_handler
}
}
Expand All @@ -141,11 +140,16 @@ impl<'a> Transaction<'a> {
impl<'a> Drop for Transaction<'a> {
fn drop(&mut self) {
if !self.committed {
self.notify_handler.call(Notification::RollingBack);
(self.notify_handler)(Notification::RollingBack);
for item in self.changes.iter().rev() {
ok_ntfy!(self.notify_handler,
Notification::NonFatalError,
item.roll_back(&self.prefix));
// ok_ntfy!(self.notify_handler,
// Notification::NonFatalError,
match item.roll_back(&self.prefix) {
Ok(()) => {}
Err(e) => {
(self.notify_handler)(Notification::NonFatalError(&e));
}
}
}
}
}
Expand All @@ -172,7 +176,7 @@ impl<'a> ChangedItem<'a> {
AddedDir(ref path) => {
try!(utils::remove_dir("component",
&prefix.abs_path(path),
rustup_utils::NotifyHandler::none()))
&|_| ()))
}
RemovedFile(ref path, ref tmp) | ModifiedFile(ref path, Some(ref tmp)) => {
try!(utils::rename_file("component", &tmp, &prefix.abs_path(path)))
Expand All @@ -198,7 +202,7 @@ impl<'a> ChangedItem<'a> {
}.into())
} else {
if let Some(p) = abs_path.parent() {
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
try!(utils::ensure_dir_exists("component", p, &|_| ()));
}
let file = try!(File::create(&abs_path)
.chain_err(|| format!("error creating file '{}'", abs_path.display())));
Expand All @@ -218,7 +222,7 @@ impl<'a> ChangedItem<'a> {
}.into())
} else {
if let Some(p) = abs_path.parent() {
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
try!(utils::ensure_dir_exists("component", p, &|_| ()));
}
try!(utils::copy_file(src, &abs_path));
Ok(ChangedItem::AddedFile(relpath))
Expand All @@ -233,9 +237,9 @@ impl<'a> ChangedItem<'a> {
}.into())
} else {
if let Some(p) = abs_path.parent() {
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
try!(utils::ensure_dir_exists("component", p, &|_| ()));
}
try!(utils::copy_dir(src, &abs_path, rustup_utils::NotifyHandler::none()));
try!(utils::copy_dir(src, &abs_path, &|_| ()));
Ok(ChangedItem::AddedDir(relpath))
}
}
Expand Down Expand Up @@ -274,7 +278,7 @@ impl<'a> ChangedItem<'a> {
Ok(ChangedItem::ModifiedFile(relpath, Some(backup)))
} else {
if let Some(p) = abs_path.parent() {
try!(utils::ensure_dir_exists("component", p, rustup_utils::NotifyHandler::none()));
try!(utils::ensure_dir_exists("component", p, &|_| {}));
}
Ok(ChangedItem::ModifiedFile(relpath, None))
}
Expand Down
20 changes: 11 additions & 9 deletions src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,19 @@ pub fn download_and_check<'a>(url_str: &str,
return Ok(None);
}
} else {
cfg.notify_handler.call(Notification::CantReadUpdateHash(hash_file));
(cfg.notify_handler)(Notification::CantReadUpdateHash(hash_file));
}
} else {
cfg.notify_handler.call(Notification::NoUpdateHash(hash_file));
(cfg.notify_handler)(Notification::NoUpdateHash(hash_file));
}
}

let url = try!(utils::parse_url(url_str));
let file = try!(cfg.temp_cfg.new_file_with_ext("", ext));

let mut hasher = Sha256::new();
try!(utils::download_file(&url, &file, Some(&mut hasher), ntfy!(&cfg.notify_handler)));
try!(utils::download_file(&url, &file, Some(&mut hasher),
&|n| (cfg.notify_handler)(n.into())));
let actual_hash = hasher.result_str();

if hash != actual_hash {
Expand All @@ -440,26 +441,27 @@ pub fn download_and_check<'a>(url_str: &str,
calculated: actual_hash,
}.into());
} else {
cfg.notify_handler.call(Notification::ChecksumValid(url_str));
(cfg.notify_handler)(Notification::ChecksumValid(url_str));
}

// TODO: Check the signature of the file

Ok(Some((file, partial_hash)))
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone)]
pub struct DownloadCfg<'a> {
pub dist_root: &'a str,
pub temp_cfg: &'a temp::Cfg,
pub notify_handler: NotifyHandler<'a>,
pub notify_handler: &'a Fn(Notification),
}

pub fn download_hash(url: &str, cfg: DownloadCfg) -> Result<String> {
let hash_url = try!(utils::parse_url(&(url.to_owned() + ".sha256")));
let hash_file = try!(cfg.temp_cfg.new_file());

try!(utils::download_file(&hash_url, &hash_file, None, ntfy!(&cfg.notify_handler)));
try!(utils::download_file(&hash_url, &hash_file, None,
&|n| (cfg.notify_handler)(n.into())));

Ok(try!(utils::read_file("hash", &hash_file).map(|s| s[0..64].to_owned())))
}
Expand All @@ -486,7 +488,7 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
};

// TODO: Add a notification about which manifest version is going to be used
download.notify_handler.call(Notification::DownloadingManifest(&toolchain_str));
(download.notify_handler)(Notification::DownloadingManifest(&toolchain_str));
match dl_v2_manifest(download, update_hash, toolchain) {
Ok(Some((m, hash))) => {
return match try!(manifestation.update(&m, changes, &download.temp_cfg,
Expand All @@ -498,7 +500,7 @@ pub fn update_from_dist<'a>(download: DownloadCfg<'a>,
Ok(None) => return Ok(None),
Err(Error(ErrorKind::Utils(::rustup_utils::ErrorKind::Download404 { .. }), _)) => {
// Proceed to try v1 as a fallback
download.notify_handler.call(Notification::DownloadingLegacyManifest);
(download.notify_handler)(Notification::DownloadingLegacyManifest);
}
Err(e) => return Err(e)
}
Expand Down
Loading