Fix compute_hash

This commit is contained in:
Vincent Prouillet 2021-02-21 09:09:02 +01:00
parent 0b94e0917d
commit 2bbd3bd424

View file

@ -100,11 +100,10 @@ where
{ {
let mut hasher = D::new(); let mut hasher = D::new();
io::copy(&mut file, &mut hasher)?; io::copy(&mut file, &mut hasher)?;
let val = format!("{:x}", hasher.finalize());
if base64 { if base64 {
Ok(encode_b64(val)) Ok(format!("{}", encode_b64(hasher.finalize())))
} else { } else {
Ok(val) Ok(format!("{:x}", hasher.finalize()))
} }
} }
@ -206,7 +205,7 @@ impl TeraFn for GetFileHash {
let f = match open_file(&self.search_paths, &path) { let f = match open_file(&self.search_paths, &path) {
Ok(f) => f, Ok(f) => f,
Err(e) => { Err(e) => {
return Err(format!("File {} could not be open {}", path, e).into()); return Err(format!("File {} could not be open: {} (searched in {:?})", path, e, self.search_paths).into());
} }
}; };
@ -897,12 +896,9 @@ title = "A title"
let static_fn = GetFileHash::new(vec![TEST_CONTEXT.static_path.clone()]); let static_fn = GetFileHash::new(vec![TEST_CONTEXT.static_path.clone()]);
let mut args = HashMap::new(); let mut args = HashMap::new();
args.insert("path".to_string(), to_value("doesnt-exist").unwrap()); args.insert("path".to_string(), to_value("doesnt-exist").unwrap());
assert_eq!( let err = format!("{}", static_fn.call(&args).unwrap_err());
format!( println!("{:?}", err);
"file `doesnt-exist` not found; searched in {}",
TEST_CONTEXT.static_path.to_str().unwrap() assert!(err.contains("File doesnt-exist could not be open"));
),
format!("{}", static_fn.call(&args).unwrap_err())
);
} }
} }