Skip to content

Commit

Permalink
Merge pull request rust-lang#1472 from mikerite/issue304
Browse files Browse the repository at this point in the history
Fix issue rust-lang#304
  • Loading branch information
Diggsey authored Jul 28, 2018
2 parents 6108e82 + 9515626 commit 22b6cdb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/rustup-utils/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@ pub fn remove_file(name: &'static str, path: &Path) -> Result<()> {
})
}

pub fn ensure_file_removed(name: &'static str, path: &Path) -> Result<()> {
let result = fs::remove_file(path);
if let Err(err) = &result {
if err.kind() == io::ErrorKind::NotFound {
return Ok(())
}
}
result.chain_err(|| ErrorKind::RemovingFile {
name: name,
path: PathBuf::from(path),
})
}

pub fn read_dir(name: &'static str, path: &Path) -> Result<fs::ReadDir> {
fs::read_dir(path).chain_err(|| ErrorKind::ReadingDirectory {
name: name,
Expand Down
2 changes: 1 addition & 1 deletion src/rustup/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'a> Toolchain<'a> {
return Ok(());
}
if let Some(update_hash) = self.update_hash()? {
utils::remove_file("update hash", &update_hash)?;
utils::ensure_file_removed("update hash", &update_hash)?;
}
let result = install::uninstall(&self.path, &|n| (self.cfg.notify_handler)(n.into()));
if !self.exists() {
Expand Down
14 changes: 14 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,20 @@ fn remove_target_host() {
});
}

#[test]
// Issue #304
fn remove_target_missing_update_hash() {
setup(&|config| {

expect_ok(config, &["rustup", "update", "nightly"]);

let file_name = format!("nightly-{}", this_host_triple());
fs::remove_file(config.rustupdir.join("update-hashes").join(file_name)).unwrap();

expect_ok(config, &["rustup", "toolchain", "remove", "nightly"]);
});
}

fn make_component_unavailable(config: &Config, name: &str, target: &TargetTriple) {
use rustup_dist::manifest::Manifest;
use rustup_mock::dist::create_hash;
Expand Down

0 comments on commit 22b6cdb

Please sign in to comment.