pxar: split assert_relative_path

the check for a single component is only required in the dir
stack atm

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2020-06-08 15:02:52 +02:00
parent c443f58b09
commit 7eacdc765b
3 changed files with 15 additions and 4 deletions

View File

@ -24,11 +24,22 @@ pub fn assert_relative_path<S: AsRef<OsStr> + ?Sized>(path: &S) -> Result<(), Er
assert_relative_path_do(Path::new(path))
}
/// Make sure path is a single component and not '.' or '..'.
pub fn assert_single_path_component<S: AsRef<OsStr> + ?Sized>(path: &S) -> Result<(), Error> {
assert_single_path_component_do(Path::new(path))
}
fn assert_relative_path_do(path: &Path) -> Result<(), Error> {
if !path.is_relative() {
bail!("bad absolute file name in archive: {:?}", path);
}
Ok(())
}
fn assert_single_path_component_do(path: &Path) -> Result<(), Error> {
assert_relative_path_do(path)?;
let mut components = path.components();
match components.next() {
Some(std::path::Component::Normal(_)) => (),