1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#[cfg(feature = "packing")]
use std::path::{Path, PathBuf};
#[cfg(feature = "packing")]
use crate::error::{UnpackingError, UnpackingResult};
#[cfg(feature = "packing")]
pub fn prune_path<P: AsRef<Path>>(mut path: PathBuf, subpath: P) -> UnpackingResult<PathBuf> {
if path.ends_with(&subpath) {
for _ in subpath.as_ref().components() {
let _ = path.pop();
}
Ok(path)
} else {
Err(UnpackingError::ManifestPathSuffixMismatch(
path,
subpath.as_ref().to_owned(),
))
}
}