Skip to content

Commit

Permalink
Add --hash flag to analyse command
Browse files Browse the repository at this point in the history
This is the command I use the most for debugging but almost all of the time taken to run it is from hashing the file. This is mitigated in other commands because the file is being hashed while it's downloading.

This makes the default behaviour to not hash the file. Using `--hash` will hash the file.
  • Loading branch information
russellbanks committed Feb 7, 2025
1 parent fb0c4ff commit 7ef4194
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/commands/analyse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ use std::fs::File;
pub struct Analyse {
#[arg(value_parser = is_valid_file, value_hint = clap::ValueHint::FilePath)]
file_path: Utf8PathBuf,

/// Hash the file and include it in the InstallerSha256 field
#[arg(long, alias = "sha256")]
hash: bool,
}

impl Analyse {
Expand All @@ -25,13 +29,14 @@ impl Analyse {
.file_path
.file_name()
.unwrap_or_else(|| self.file_path.as_str());
let analyser = FileAnalyser::new(&mmap, file_name)?;
let mut installers = analyser.installers;
let sha_256 = Sha256String::from_hasher(&Sha256::digest(&mmap))?;
for installer in &mut installers {
installer.sha_256 = sha_256.clone();
let mut analyser = FileAnalyser::new(&mmap, file_name)?;
if self.hash {
let sha_256 = Sha256String::from_hasher(&Sha256::digest(&mmap))?;
for installer in &mut analyser.installers {
installer.sha_256 = sha_256.clone();
}
}
let yaml = match installers.as_slice() {
let yaml = match analyser.installers.as_slice() {
[installer] => serde_yaml::to_string(installer)?,
installers => serde_yaml::to_string(installers)?,
};
Expand Down

0 comments on commit 7ef4194

Please sign in to comment.