Skip to content

Commit 22b6cdb

Browse files
authored
Merge pull request #1472 from mikerite/issue304
Fix issue #304
2 parents 6108e82 + 9515626 commit 22b6cdb

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/rustup-utils/src/utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@ pub fn remove_file(name: &'static str, path: &Path) -> Result<()> {
326326
})
327327
}
328328

329+
pub fn ensure_file_removed(name: &'static str, path: &Path) -> Result<()> {
330+
let result = fs::remove_file(path);
331+
if let Err(err) = &result {
332+
if err.kind() == io::ErrorKind::NotFound {
333+
return Ok(())
334+
}
335+
}
336+
result.chain_err(|| ErrorKind::RemovingFile {
337+
name: name,
338+
path: PathBuf::from(path),
339+
})
340+
}
341+
329342
pub fn read_dir(name: &'static str, path: &Path) -> Result<fs::ReadDir> {
330343
fs::read_dir(path).chain_err(|| ErrorKind::ReadingDirectory {
331344
name: name,

src/rustup/toolchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a> Toolchain<'a> {
9494
return Ok(());
9595
}
9696
if let Some(update_hash) = self.update_hash()? {
97-
utils::remove_file("update hash", &update_hash)?;
97+
utils::ensure_file_removed("update hash", &update_hash)?;
9898
}
9999
let result = install::uninstall(&self.path, &|n| (self.cfg.notify_handler)(n.into()));
100100
if !self.exists() {

tests/cli-v2.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,20 @@ fn remove_target_host() {
783783
});
784784
}
785785

786+
#[test]
787+
// Issue #304
788+
fn remove_target_missing_update_hash() {
789+
setup(&|config| {
790+
791+
expect_ok(config, &["rustup", "update", "nightly"]);
792+
793+
let file_name = format!("nightly-{}", this_host_triple());
794+
fs::remove_file(config.rustupdir.join("update-hashes").join(file_name)).unwrap();
795+
796+
expect_ok(config, &["rustup", "toolchain", "remove", "nightly"]);
797+
});
798+
}
799+
786800
fn make_component_unavailable(config: &Config, name: &str, target: &TargetTriple) {
787801
use rustup_dist::manifest::Manifest;
788802
use rustup_mock::dist::create_hash;

0 commit comments

Comments
 (0)