use object_store::path::Path;
pub(crate) fn prefixed_path(base: &Path, location: &Path) -> Path {
if base.as_ref().is_empty() {
return location.clone();
}
if location.as_ref().is_empty() {
return base.clone();
}
let joined = format!("{}/{}", base.as_ref(), location.as_ref());
Path::from(joined)
}
pub(crate) fn relativize_path(
base_dir: &Path,
full_path: Path, store_name_for_error: &'static str,
) -> object_store::Result<Path> {
if base_dir.as_ref().is_empty() {
return Ok(full_path);
}
match full_path.prefix_match(base_dir) {
Some(iter) => Ok(Path::from_iter(iter)),
None => Err(object_store::Error::Generic {
store: store_name_for_error,
source: format!(
"Internal logic error: expected base_dir '{}' to be a prefix of '{}', but it was not. Cannot relativize path.",
base_dir, full_path
).into(),
}),
}
}