FZ7MXL3BGIDZEEEKWX4CHAKPDO46FFF5BZDL6S2KOWTZ53GE7D6AC
fn find_tag(tag_path: &mut PathBuf, tag: &str) -> Result<libpijul::Hash, anyhow::Error> {
let (a, b) = tag.split_at(2);
tag_path.push(a);
let mut result = None;
for f in std::fs::read_dir(&tag_path)? {
let e = f?;
let p = if let Ok(p) = e.file_name().into_string() {
p
} else {
continue;
};
if p.starts_with(b) {
if result.is_none() {
result = Some(p)
} else {
bail!("Ambiguous tag hash");
}
}
}
if let Some(mut r) = result {
tag_path.push(&r);
if let Some(i) = r.find('.') {
r.truncate(i)
}
let f = format!("{}{}", a, r);
if let Some(h) = libpijul::Hash::from_base32(f.as_bytes()) {
return Ok(h);
}
}
bail!("Tag not found")
}