krabka_object_store/prefix.rs
1//! Helpers for addressing keys beneath a configured object-store prefix.
2
3use object_store::path::Path;
4
5/// Trim whitespace and separators copied from a console URL so `/tier/`,
6/// `tier`, and ` tier/ ` address the same root. Empty prefixes mean no prefix.
7#[must_use]
8pub fn normalize_prefix(prefix: Option<&str>) -> Option<String> {
9 let trimmed = prefix?.trim().trim_matches('/');
10 (!trimmed.is_empty()).then(|| trimmed.to_owned())
11}
12
13/// Build the absolute object key for a path relative to an archive root.
14#[must_use]
15pub fn prefixed_key(prefix: Option<&str>, relative: &str) -> Path {
16 prefix.map_or_else(
17 || Path::from(relative),
18 |prefix| Path::from(format!("{prefix}/{relative}")),
19 )
20}