Detect hash collisions and produce an error.

This commit is contained in:
Mario Carbajal 2024-01-20 00:48:07 -03:00
parent e240c0aba4
commit c0c95d8a80
1 changed files with 15 additions and 0 deletions

View File

@ -1,5 +1,7 @@
use anyhow::bail;
use std::{
borrow::Cow,
collections::HashMap,
fs::{self, File},
io::{BufWriter, Write},
path::{Path, PathBuf},
@ -115,6 +117,19 @@ fn run(run_params: &RunParams) -> anyhow::Result<()> {
}
}
{
let mut map = HashMap::new();
for file in modified_css_files.iter() {
if let Some(previous_file) = map.insert(&file.hash, file) {
bail!(
"The following files had a hash collision:\n{}\n{}\nConsider increasing the hash_len setting.",
file.path.to_string_lossy(),
previous_file.path.to_string_lossy()
);
}
}
}
if let Some(output_file) = &run_params.config.output_file {
if let Some(parent) = output_file.parent() {
fs::create_dir_all(parent)?;