diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs index b1245c5f..bea37ee1 100644 --- a/pbs-client/src/pxar/extract.rs +++ b/pbs-client/src/pxar/extract.rs @@ -29,8 +29,8 @@ use proxmox_compression::zip::{ZipEncoder, ZipEntry}; use crate::pxar::dir_stack::PxarDirStack; use crate::pxar::metadata; +use crate::pxar::tools::handle_root_with_optional_format_version_prelude; use crate::pxar::Flags; -use crate::tools::handle_root_with_optional_format_version_prelude; pub struct PxarExtractOptions<'a> { pub match_list: &'a [MatchEntry], diff --git a/pbs-client/src/pxar/tools.rs b/pbs-client/src/pxar/tools.rs index c444a894..2f517022 100644 --- a/pbs-client/src/pxar/tools.rs +++ b/pbs-client/src/pxar/tools.rs @@ -339,3 +339,39 @@ pub async fn pxar_metadata_catalog_lookup( Ok(entries) } + +/// Decode possible format version and prelude entries before getting the root directory +/// entry. +/// +/// Returns the root directory entry and, if present, the prelude entry +pub fn handle_root_with_optional_format_version_prelude( + decoder: &mut pxar::decoder::sync::Decoder, +) -> Result<(pxar::Entry, Option), Error> { + let first = decoder + .next() + .ok_or_else(|| format_err!("missing root entry"))??; + match first.kind() { + pxar::EntryKind::Directory => { + let version = pxar::format::FormatVersion::Version1; + log::debug!("pxar format version '{version:?}'"); + Ok((first, None)) + } + pxar::EntryKind::Version(version) => { + log::debug!("pxar format version '{version:?}'"); + let second = decoder + .next() + .ok_or_else(|| format_err!("missing root entry"))??; + match second.kind() { + pxar::EntryKind::Directory => Ok((second, None)), + pxar::EntryKind::Prelude(_prelude) => { + let third = decoder + .next() + .ok_or_else(|| format_err!("missing root entry"))??; + Ok((third, Some(second))) + } + _ => bail!("unexpected entry kind {:?}", second.kind()), + } + } + _ => bail!("unexpected entry kind {:?}", first.kind()), + } +} diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs index 87e74de6..28db6f34 100644 --- a/pbs-client/src/tools/mod.rs +++ b/pbs-client/src/tools/mod.rs @@ -596,42 +596,6 @@ pub fn has_pxar_filename_extension(name: &str, with_didx_extension: bool) -> boo } } -/// Decode possible format version and prelude entries before getting the root directory -/// entry. -/// -/// Returns the root directory entry and, if present, the prelude entry -pub fn handle_root_with_optional_format_version_prelude( - decoder: &mut pxar::decoder::sync::Decoder, -) -> Result<(pxar::Entry, Option), Error> { - let first = decoder - .next() - .ok_or_else(|| format_err!("missing root entry"))??; - match first.kind() { - pxar::EntryKind::Directory => { - let version = pxar::format::FormatVersion::Version1; - log::debug!("pxar format version '{version:?}'"); - Ok((first, None)) - } - pxar::EntryKind::Version(version) => { - log::debug!("pxar format version '{version:?}'"); - let second = decoder - .next() - .ok_or_else(|| format_err!("missing root entry"))??; - match second.kind() { - pxar::EntryKind::Directory => Ok((second, None)), - pxar::EntryKind::Prelude(_prelude) => { - let third = decoder - .next() - .ok_or_else(|| format_err!("missing root entry"))??; - Ok((third, Some(second))) - } - _ => bail!("unexpected entry kind {:?}", second.kind()), - } - } - _ => bail!("unexpected entry kind {:?}", first.kind()), - } -} - /// Raise the soft limit for open file handles to the hard limit /// /// Returns the values set before raising the limit as libc::rlimit64 diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index b28db6e3..f7481bac 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -25,7 +25,7 @@ use pbs_api_types::{ PRIV_DATASTORE_MODIFY, PRIV_TAPE_READ, TAPE_RESTORE_NAMESPACE_SCHEMA, TAPE_RESTORE_SNAPSHOT_SCHEMA, UPID_SCHEMA, }; -use pbs_client::tools::handle_root_with_optional_format_version_prelude; +use pbs_client::pxar::tools::handle_root_with_optional_format_version_prelude; use pbs_config::CachedUserInfo; use pbs_datastore::dynamic_index::DynamicIndexReader; use pbs_datastore::fixed_index::FixedIndexReader;