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
3 changes: 1 addition & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ error-chain = "0.12"
effective-limits = "0.5"
flate2 = "1"
git-testament = "0.1.4"
home = "0.5"
home = { git = "https://github.com/rbtcollins/home", rev="81c8dfcd815765daf384319a04e237feb9d5e72d" }
lazy_static = "1"
libc = "0.2"
num_cpus = "1.13"
Expand Down
1 change: 1 addition & 0 deletions src/cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ error_chain! {
}

foreign_links {
Clap(clap::Error);
Temp(temp::Error);
Io(io::Error);
Term(term::Error);
Expand Down
11 changes: 10 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ where
pub fn main() -> Result<utils::ExitCode> {
self_update::cleanup_self_updater()?;

let matches = cli().get_matches_from(process().args_os());
let matches = match cli().get_matches_from_safe(process().args_os()) {
Ok(matches) => Ok(matches),
Err(e)
if e.kind == clap::ErrorKind::HelpDisplayed
|| e.kind == clap::ErrorKind::VersionDisplayed =>
{
return Ok(utils::ExitCode(0))
}
Err(e) => Err(e),
}?;
Comment on lines +58 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to have this factored into a function given it's also used in setup_mode.rs and someone fixing something in one might miss the other.

let verbose = matches.is_present("verbose");
let quiet = matches.is_present("quiet");
let cfg = &mut common::set_globals(verbose, quiet)?;
Expand Down
11 changes: 10 additions & 1 deletion src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ pub fn main() -> Result<utils::ExitCode> {
.help("Don't configure the PATH environment variable"),
);

let matches = cli.get_matches_from(process().args_os());
let matches = match cli.get_matches_from_safe(process().args_os()) {
Ok(matches) => matches,
Err(e)
if e.kind == clap::ErrorKind::HelpDisplayed
|| e.kind == clap::ErrorKind::VersionDisplayed =>
{
return Ok(utils::ExitCode(0))
}
Err(e) => Err(e)?,
};
let no_prompt = matches.is_present("no-prompt");
let verbose = matches.is_present("verbose");
let quiet = matches.is_present("quiet");
Expand Down
3 changes: 2 additions & 1 deletion src/cli/topical_doc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::errors::*;
use std::ffi::OsString;
use std::fs;
use std::path::{Path, PathBuf};

use super::errors::*;

struct DocData<'a> {
topic: &'a str,
subtopic: &'a str,
Expand Down
17 changes: 17 additions & 0 deletions src/currentprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use rand::{thread_rng, Rng};
pub mod argsource;
pub mod cwdsource;
pub mod filesource;
mod homethunk;
pub mod varsource;

use argsource::*;
Expand Down Expand Up @@ -193,6 +194,22 @@ impl TestProcess {
let high_bits = rng.gen_range(0, u32::MAX) as u64;
high_bits << 32 | low_bits
}

/// Extracts the stdout from the process
pub fn get_stdout(&self) -> Vec<u8> {
self.stdout
.lock()
.unwrap_or_else(|e| e.into_inner())
.clone()
}

/// Extracts the stderr from the process
pub fn get_stderr(&self) -> Vec<u8> {
self.stderr
.lock()
.unwrap_or_else(|e| e.into_inner())
.clone()
}
}

impl ProcessSource for TestProcess {
Expand Down
21 changes: 21 additions & 0 deletions src/currentprocess/homethunk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// Adapts currentprocess to the trait home::Env
use std::ffi::OsString;
use std::io;
use std::ops::Deref;
use std::path::PathBuf;

use super::CurrentDirSource;
use super::CurrentProcess;
use super::VarSource;

impl home::Env for Box<dyn CurrentProcess + 'static> {
fn home_dir(&self) -> Option<PathBuf> {
self.var("HOME").ok().map(|v| v.into())
}
fn current_dir(&self) -> Result<PathBuf, io::Error> {
CurrentDirSource::current_dir(self.deref())
}
fn var_os(&self, key: &str) -> Option<OsString> {
VarSource::var_os(self.deref(), key)
}
}
23 changes: 19 additions & 4 deletions src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,22 @@ where
}

pub fn remove_file(name: &'static str, path: &Path) -> Result<()> {
fs::remove_file(path).chain_err(|| ErrorKind::RemovingFile {
// Most files we go to remove won't ever be in use. Some, like proxies, may
// be for indefinite periods, and this will mean we are slower to error and
// have the user fix the issue. Others, like the setup binary, are
// transiently in use, and this wait loop will fix the issue transparently
// for a rare performance hit.
retry(
Fibonacci::from_millis(1).map(jitter).take(10),
|| match fs::remove_file(path) {
Ok(()) => OperationResult::Ok(()),
Err(e) => match e.kind() {
io::ErrorKind::PermissionDenied => OperationResult::Retry(e),
_ => OperationResult::Err(e),
},
},
)
.chain_err(|| ErrorKind::RemovingFile {
name,
path: PathBuf::from(path),
})
Expand Down Expand Up @@ -466,11 +481,11 @@ pub fn to_absolute<P: AsRef<Path>>(path: P) -> Result<PathBuf> {
}

pub fn home_dir() -> Option<PathBuf> {
home::home_dir()
home::home_dir_from(&process())
}

pub fn cargo_home() -> Result<PathBuf> {
home::cargo_home().map_err(|e| Error::from_kind(ErrorKind::Io(e)))
home::cargo_home_from(&process()).map_err(|e| Error::from_kind(ErrorKind::Io(e)))
}

// Creates a ~/.rustup folder
Expand All @@ -496,7 +511,7 @@ pub fn rustup_home_in_user_dir() -> Result<PathBuf> {
}

pub fn rustup_home() -> Result<PathBuf> {
home::rustup_home().map_err(|e| Error::from_kind(ErrorKind::Io(e)))
home::rustup_home_from(&process()).map_err(|e| Error::from_kind(ErrorKind::Io(e)))
}

pub fn format_path_for_display(path: &str) -> String {
Expand Down
Loading