This commit is contained in:
Lucy 2025-09-30 17:08:26 +02:00
parent 0d177729ab
commit 9670deab55
4 changed files with 465 additions and 46 deletions

View file

@ -15,45 +15,4 @@ pub fn get_md5sums() -> Result<String, Box<dyn std::error::Error>> {
Ok(res)
}
pub fn save_md5sums(content: &str, path: &Path) -> Result<(), Box<dyn std::error::Error>> {
std::fs::write(path, content)?;
Ok(())
}
pub fn verify_md5sums(
md5_file: &Path,
sources_dir: &Path,
) -> Result<(), Box<dyn std::error::Error>> {
let file = File::open(md5_file)?;
for line in BufReader::new(file).lines() {
let line = line?;
if line.trim().is_empty() {
continue;
}
let mut parts = line.split_whitespace();
let expected_hash = parts.next().ok_or("Malformed md5sums line")?;
let filename = parts.next().ok_or("Malformed md5sums line")?;
let file_path = sources_dir.join(filename);
let mut f = File::open(&file_path)?;
let mut buffer = Vec::new();
f.read_to_end(&mut buffer)?;
let digest = md5::compute(&buffer);
let hex = format!("{:x}", digest);
if hex == expected_hash {
println!("{} {} OK", style("").green(), filename);
} else {
println!(
"{} {} FAILED (expected {}, got {})",
style("").red(),
filename,
expected_hash,
hex
);
}
}
Ok(())
}