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
27 changes: 2 additions & 25 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 @@ -44,7 +44,7 @@ semver = "0.9"
sha2 = "0.8"
strsim = "0.9.1"
tar = "0.4.26"
tempdir = "0.3.4"
tempfile = "3.1"
# FIXME(issue #1788)
term = "=0.5.1"
threadpool = "1"
Expand Down
2 changes: 1 addition & 1 deletion download/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ reqwest = { version = "0.9.14", features = ["socks"], optional = true }
[dev-dependencies]
futures = "0.1"
hyper = "0.12"
tempdir = "0.3.4"
tempfile = "3"
7 changes: 5 additions & 2 deletions download/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ use std::net::SocketAddr;
use std::path::Path;

use futures::sync::oneshot;
use tempdir::TempDir;
use tempfile::TempDir;

pub fn tmp_dir() -> TempDir {
TempDir::new("rustup-download-test-").expect("creating tempdir for test")
tempfile::Builder::new()
.prefix("rustup-download-test-")
.tempdir()
.expect("creating tempdir for test")
}

pub fn write_file(path: &Path, contents: &str) {
Expand Down
10 changes: 6 additions & 4 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ pub fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermission> {
}
let current_exe = env::current_exe()?;
let current_exe_dir = current_exe.parent().expect("Rustup isn't in a directory‽");
match tempdir::TempDir::new_in(current_exe_dir, "updtest") {
Ok(_) => {}
Err(e) => match e.kind() {
if let Err(e) = tempfile::Builder::new()
.prefix("updtest")
.tempdir_in(current_exe_dir)
{
match e.kind() {
ErrorKind::PermissionDenied => {
debug!("Skipping self-update because we cannot write to the rustup dir");
if explicit {
Expand All @@ -270,7 +272,7 @@ pub fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermission> {
}
}
_ => Err(e)?,
},
}
}
Ok(SelfUpdatePermission::Permit)
}
Expand Down
6 changes: 4 additions & 2 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use std::env::consts::EXE_SUFFIX;
use std::fs;
use std::path::{Component, Path, PathBuf};
use std::process::{self, Command};
use tempdir::TempDir;

pub struct InstallOpts {
pub default_host_triple: String,
Expand Down Expand Up @@ -1457,7 +1456,10 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {

let update_root = env::var("RUSTUP_UPDATE_ROOT").unwrap_or_else(|_| String::from(UPDATE_ROOT));

let tempdir = TempDir::new("rustup-update").chain_err(|| "error creating temp directory")?;
let tempdir = tempfile::Builder::new()
.prefix("rustup-update")
.tempdir()
.chain_err(|| "error creating temp directory")?;

// Get current version
let current_version = env!("CARGO_PKG_VERSION");
Expand Down
20 changes: 16 additions & 4 deletions tests/cli-exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ info: you may use `--path <path>` option to remove override toolchain for a spec
fn remove_override_with_path() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let dir = tempdir::TempDir::new("rustup-test").unwrap();
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
config.change_dir(dir.path(), || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
});
Expand Down Expand Up @@ -190,7 +193,10 @@ fn remove_override_with_path_deleted() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let path = {
let dir = tempdir::TempDir::new("rustup-test").unwrap();
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
let path = std::fs::canonicalize(dir.path()).unwrap();
config.change_dir(&path, || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
Expand Down Expand Up @@ -222,7 +228,10 @@ fn remove_override_nonexistent() {
for keyword in &["remove", "unset"] {
setup(&|config| {
let path = {
let dir = tempdir::TempDir::new("rustup-test").unwrap();
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
let path = std::fs::canonicalize(dir.path()).unwrap();
config.change_dir(&path, || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
Expand Down Expand Up @@ -276,7 +285,10 @@ fn list_overrides_with_nonexistent() {
let trip = this_host_triple();

let nonexistent_path = {
let dir = tempdir::TempDir::new("rustup-test").unwrap();
let dir = tempfile::Builder::new()
.prefix("rustup-test")
.tempdir()
.unwrap();
config.change_dir(dir.path(), || {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
});
Expand Down
16 changes: 12 additions & 4 deletions tests/cli-misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustup::errors::TOOLSTATE_MSG;
use rustup::utils::{raw, utils};

use std::env::consts::EXE_SUFFIX;
use tempdir::TempDir;

macro_rules! for_host {
($s: expr) => {
Expand Down Expand Up @@ -571,7 +570,10 @@ fn rename_rls_remove() {

#[test]
fn install_stops_if_rustc_exists() {
let temp_dir = TempDir::new("fakebin").unwrap();
let temp_dir = tempfile::Builder::new()
.prefix("fakebin")
.tempdir()
.unwrap();
// Create fake executable
let fake_exe = temp_dir.path().join(&format!("{}{}", "rustc", EXE_SUFFIX));
raw::append_file(&fake_exe, "").unwrap();
Expand Down Expand Up @@ -600,7 +602,10 @@ fn install_stops_if_rustc_exists() {

#[test]
fn install_stops_if_cargo_exists() {
let temp_dir = TempDir::new("fakebin").unwrap();
let temp_dir = tempfile::Builder::new()
.prefix("fakebin")
.tempdir()
.unwrap();
// Create fake executable
let fake_exe = temp_dir.path().join(&format!("{}{}", "cargo", EXE_SUFFIX));
raw::append_file(&fake_exe, "").unwrap();
Expand Down Expand Up @@ -629,7 +634,10 @@ fn install_stops_if_cargo_exists() {

#[test]
fn with_no_prompt_install_succeeds_if_rustc_exists() {
let temp_dir = TempDir::new("fakebin").unwrap();
let temp_dir = tempfile::Builder::new()
.prefix("fakebin")
.tempdir()
.unwrap();
// Create fake executable
let fake_exe = temp_dir.path().join(&format!("{}{}", "rustc", EXE_SUFFIX));
raw::append_file(&fake_exe, "").unwrap();
Expand Down
11 changes: 8 additions & 3 deletions tests/cli-self-upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::fs;
use std::path::Path;
use std::process::Command;
use std::sync::Mutex;
use tempdir::TempDir;

macro_rules! for_host {
($s: expr) => {
Expand Down Expand Up @@ -48,7 +47,10 @@ pub fn setup(f: &dyn Fn(&Config)) {
pub fn update_setup(f: &dyn Fn(&Config, &Path)) {
setup(&|config| {
// Create a mock self-update server
let self_dist_tmp = TempDir::new("self_dist").unwrap();
let self_dist_tmp = tempfile::Builder::new()
.prefix("self_dist")
.tempdir()
.unwrap();
let self_dist = self_dist_tmp.path();

let trip = this_host_triple();
Expand Down Expand Up @@ -380,7 +382,10 @@ fn install_with_zsh_adds_path_to_zprofile() {
#[cfg(unix)]
fn install_with_zsh_adds_path_to_zdotdir_zprofile() {
setup(&|config| {
let zdotdir = TempDir::new("zdotdir").unwrap();
let zdotdir = tempfile::Builder::new()
.prefix("zdotdir")
.tempdir()
.unwrap();
let my_rc = "foo\nbar\nbaz";
let rc = zdotdir.path().join(".zprofile");
raw::write_file(&rc, my_rc).unwrap();
Expand Down
19 changes: 9 additions & 10 deletions tests/cli-v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::mock::clitools::{
this_host_triple, Config, Scenario,
};
use std::fs;
use tempdir::TempDir;

macro_rules! for_host {
($s: expr) => {
Expand Down Expand Up @@ -145,7 +144,7 @@ fn remove_default_toolchain_err_handling() {
#[test]
fn remove_override_toolchain_err_handling() {
setup(&|config| {
let tempdir = TempDir::new("rustup").unwrap();
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
config.change_dir(tempdir.path(), &|| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "override", "add", "beta"]);
Expand Down Expand Up @@ -223,7 +222,7 @@ fn install_override_toolchain_from_version() {
#[test]
fn override_overrides_default() {
setup(&|config| {
let tempdir = TempDir::new("rustup").unwrap();
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
expect_ok(config, &["rustup", "default", "nightly"]);
config.change_dir(tempdir.path(), &|| {
expect_ok(config, &["rustup", "override", "add", "beta"]);
Expand All @@ -235,8 +234,8 @@ fn override_overrides_default() {
#[test]
fn multiple_overrides() {
setup(&|config| {
let tempdir1 = TempDir::new("rustup").unwrap();
let tempdir2 = TempDir::new("rustup").unwrap();
let tempdir1 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let tempdir2 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();

expect_ok(config, &["rustup", "default", "nightly"]);
config.change_dir(tempdir1.path(), &|| {
Expand All @@ -260,7 +259,7 @@ fn multiple_overrides() {
#[test]
fn change_override() {
setup(&|config| {
let tempdir = TempDir::new("rustup").unwrap();
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
config.change_dir(tempdir.path(), &|| {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
expect_ok(config, &["rustup", "override", "add", "beta"]);
Expand All @@ -272,7 +271,7 @@ fn change_override() {
#[test]
fn remove_override_no_default() {
setup(&|config| {
let tempdir = TempDir::new("rustup").unwrap();
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
config.change_dir(tempdir.path(), &|| {
expect_ok(config, &["rustup", "override", "add", "nightly"]);
expect_ok(config, &["rustup", "override", "remove"]);
Expand All @@ -284,7 +283,7 @@ fn remove_override_no_default() {
#[test]
fn remove_override_with_default() {
setup(&|config| {
let tempdir = TempDir::new("rustup").unwrap();
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
config.change_dir(tempdir.path(), &|| {
expect_ok(config, &["rustup", "default", "nightly"]);
expect_ok(config, &["rustup", "override", "add", "beta"]);
Expand All @@ -297,8 +296,8 @@ fn remove_override_with_default() {
#[test]
fn remove_override_with_multiple_overrides() {
setup(&|config| {
let tempdir1 = TempDir::new("rustup").unwrap();
let tempdir2 = TempDir::new("rustup").unwrap();
let tempdir1 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let tempdir2 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
expect_ok(config, &["rustup", "default", "nightly"]);
config.change_dir(tempdir1.path(), &|| {
expect_ok(config, &["rustup", "override", "add", "beta"]);
Expand Down
Loading