1use md5::{Digest, Md5};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone)]
6pub struct Dependency {
7 pub name: std::path::PathBuf,
8 pub hash: String,
9}
10
11impl Dependency {
12 pub fn compute_hash(&self) -> String {
14 let mut hasher = Md5::new();
15 std::fs::File::open(&self.name)
16 .and_then(|mut file| std::io::copy(&mut file, &mut hasher))
17 .map(|_| base16ct::lower::encode_string(&hasher.finalize()))
18 .unwrap_or(String::new())
19 }
20
21 pub fn update_hash(&mut self) {
23 self.hash = self.compute_hash();
24 }
25
26 pub fn needs_update(&self) -> bool {
29 self.compute_hash() != self.hash
30 }
31}