use std::path::{Component, Path};
use camino::Utf8PathBuf;
pub const ALLOWED_PREFIXES: [&str; 2] = ["lib/", "share/extension/"];
#[must_use]
pub fn classify_entry_path(raw: &Path) -> Option<Utf8PathBuf> {
let parts = normal_components(raw)?;
is_allowed_layout(&parts).then(|| Utf8PathBuf::from(parts.join("/")))
}
fn normal_components(raw: &Path) -> Option<Vec<&str>> {
let mut parts = Vec::new();
for (index, component) in raw.components().enumerate() {
match component {
Component::CurDir if index == 0 => {}
Component::Normal(part) => parts.push(plain_component(part.to_str()?)?),
_ => return None,
}
}
Some(parts)
}
fn plain_component(part: &str) -> Option<&str> {
(!part.contains('\\') && !part.contains('/')).then_some(part)
}
fn is_allowed_layout(parts: &[&str]) -> bool {
matches!(parts, ["lib", _] | ["share", "extension", _, ..])
}