Skip to content

Commit

Permalink
only show toolchain list once when using --installed
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Feb 1, 2023
1 parent a36602f commit a855ca3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
31 changes: 16 additions & 15 deletions src/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,36 +390,37 @@ fn rustup_toolchain_list() -> Option<Vec<String>> {
}
}

pub fn remove_not_built_with(
dir: &Path,
rust_version_to_keep: &[String],
dry_run: bool,
) -> Result<u64, Error> {
debug!("cleaning: {:?} with remove_not_built_with", dir);
let mut total_disk_space = 0;
let hashed_rust_version_to_keep = if !rust_version_to_keep.is_empty() {
info!(
"Using specified installed toolchains: {:?}",
rust_version_to_keep
);
lookup_from_names(rust_version_to_keep.iter().map(Some))?
pub fn hash_toolchains(rust_versions: Option<&Vec<String>>) -> Result<HashSet<u64>, Error> {
let hashed_versions = if let Some(versions) = rust_versions {
info!("Using specified installed toolchains: {:?}", versions);
lookup_from_names(versions.iter().map(Some))?
} else {
match rustup_toolchain_list() {
Some(list) => {
info!("Using all installed toolchains: {:?}", list);
lookup_from_names(list.iter().map(Some))?
}

None => {
info!("Couldn't identify the installed toolchains, using bare `rustc` call");
let list: Vec<Option<String>> = vec![None];
lookup_from_names(list.into_iter())?
}
}
};

Ok(hashed_versions)
}

pub fn remove_not_built_with(
dir: &Path,
hashed_rust_version_to_keep: &HashSet<u64>,
dry_run: bool,
) -> Result<u64, Error> {
debug!("cleaning: {:?} with remove_not_built_with", dir);
let mut total_disk_space = 0;
for fing in lookup_all_fingerprint_dirs(dir) {
let path = fing.into_path();
let keep = load_all_fingerprints_built_with(&path, &hashed_rust_version_to_keep)?;
let keep = load_all_fingerprints_built_with(&path, hashed_rust_version_to_keep)?;
total_disk_space +=
remove_not_built_with_in_a_profile(path.parent().unwrap(), &keep, dry_run)?;
}
Expand Down
12 changes: 8 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ mod stamp;
mod util;

use self::cli::Criterion;
use self::fingerprint::{remove_not_built_with, remove_older_than, remove_older_until_fits};
use self::fingerprint::{
hash_toolchains, remove_not_built_with, remove_older_than, remove_older_until_fits,
};
use self::stamp::Timestamp;
use self::util::format_bytes;

Expand Down Expand Up @@ -164,13 +166,15 @@ fn main() -> anyhow::Result<()> {
};

let toolchains = match &criterion {
Criterion::Installed => Some(vec![]),
Criterion::Toolchains(vec) => Some(vec).cloned(),
Criterion::Installed => Some(None),
Criterion::Toolchains(vec) => Some(Some(vec.clone())),
_ => None,
};
if let Some(toolchains) = toolchains {
let hashed_toolchains = hash_toolchains(toolchains.as_ref())?;

for project_path in &paths {
match remove_not_built_with(project_path, &toolchains, dry_run) {
match remove_not_built_with(project_path, &hashed_toolchains, dry_run) {
Ok(cleaned_amount) if dry_run => {
info!(
"Would clean: {} from {project_path:?}",
Expand Down

0 comments on commit a855ca3

Please sign in to comment.