use crate::{
block_read::BlockRead,
dir::{read_entries, EntrySet},
error::{Error, Result},
name::name_eq,
path::Path,
upcase::Upcase,
vbr::Geometry,
};
pub(crate) fn resolve(
reader: &mut impl BlockRead,
geo: &Geometry,
upcase: &Upcase,
path: Path<'_>,
) -> Result<Option<EntrySet>> {
let mut cluster = geo.root_cluster;
let mut contiguous = false; let mut found: Option<EntrySet> = None;
for comp in path.components() {
if let Some(es) = &found {
if !es.is_dir {
return Err(Error::NotFound {
component: "non-directory in path",
});
}
}
let entries = read_entries(reader, geo, cluster, contiguous)?;
let next = entries
.into_iter()
.find(|es| name_eq(comp, &es.name, upcase))
.ok_or(Error::NotFound { component: "path" })?;
cluster = next.first_cluster;
contiguous = next.contiguous;
found = Some(next);
}
Ok(found)
}