Skip to content

Commit

Permalink
Delete content of downloads & tmp dirs after full rustup update
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniCheni committed Oct 18, 2019
1 parent d8511f2 commit 0db473b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,9 @@ fn update(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
}
} else {
common::update_all_channels(cfg, self_update, m.is_present("force"))?;
info!("cleaning up downloads & tmp directories");
utils::delete_dir_contents(&cfg.download_dir);
cfg.temp_cfg.clean();
}

Ok(())
Expand Down
5 changes: 5 additions & 0 deletions src/dist/temp.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::raw;
use crate::utils::utils;
use std::error;
use std::fmt::{self, Display};
use std::fs;
Expand Down Expand Up @@ -196,6 +197,10 @@ impl Cfg {
}
}
}

pub fn clean(&self) {
utils::delete_dir_contents(&self.root_directory);
}
}

impl fmt::Debug for Cfg {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,22 @@ where
})
}

pub fn delete_dir_contents(dir_path: &Path) {
let dir_contents = fs::read_dir(dir_path);
if let Ok(contents) = dir_contents {
for entry in contents {
if let Ok(entry) = entry {
let path = entry.path();
if path.is_dir() {
remove_dir_all::remove_dir_all(path).expect("Failed to remove a dir");
} else {
fs::remove_file(path).expect("Failed to remove a file");
}
};
}
};
}

pub struct FileReaderWithProgress<'a> {
fh: std::io::BufReader<std::fs::File>,
notify_handler: &'a dyn Fn(Notification<'_>),
Expand Down
6 changes: 6 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: cleaning up downloads & tmp directories
"
),
);
Expand Down Expand Up @@ -98,6 +99,7 @@ info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: cleaning up downloads & tmp directories
"
),
);
Expand All @@ -120,6 +122,7 @@ fn rustup_stable_no_change() {
),
for_host!(
r"info: syncing channel updates for 'stable-{0}'
info: cleaning up downloads & tmp directories
"
),
);
Expand Down Expand Up @@ -188,6 +191,7 @@ info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: cleaning up downloads & tmp directories
"
),
);
Expand Down Expand Up @@ -244,6 +248,7 @@ info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: cleaning up downloads & tmp directories
"
),
);
Expand All @@ -260,6 +265,7 @@ fn rustup_no_channels() {
&["rustup", "update", "--no-self-update"],
r"",
r"info: no updatable toolchains installed
info: cleaning up downloads & tmp directories
",
);
})
Expand Down

0 comments on commit 0db473b

Please sign in to comment.