[pbs-devel] [PATCH v4 proxmox-backup 03/10] client: tools: move pxar root entry helper to pxar module
Christian Ebner
c.ebner at proxmox.com
Mon Oct 21 17:47:37 CEST 2024
Move the `handle_root_with_optional_format_version_prelude` helper,
purely related to handling the root entry for pxar format version 2
archives, to the more fitting pxar tools submodule.
This is for code cleanup purposes only.
No functional changes.
Suggested-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 3:
- s/submodule/module
- Reword commit message in order to clarify intend of this and
subsequent patches
- Add missing git trailers
changes since version 2:
- not present in previous version
pbs-client/src/pxar/extract.rs | 2 +-
pbs-client/src/pxar/tools.rs | 36 ++++++++++++++++++++++++++++++++++
pbs-client/src/tools/mod.rs | 36 ----------------------------------
src/api2/tape/restore.rs | 2 +-
4 files changed, 38 insertions(+), 38 deletions(-)
diff --git a/pbs-client/src/pxar/extract.rs b/pbs-client/src/pxar/extract.rs
index b1245c5fc..bea37ee10 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 c444a8941..2f517022f 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<T: Clone + ReadAt>(
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<R: pxar::decoder::SeqRead>(
+ decoder: &mut pxar::decoder::sync::Decoder<R>,
+) -> Result<(pxar::Entry, Option<pxar::Entry>), 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 87e74de6e..28db6f348 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<R: pxar::decoder::SeqRead>(
- decoder: &mut pxar::decoder::sync::Decoder<R>,
-) -> Result<(pxar::Entry, Option<pxar::Entry>), 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 b28db6e39..f7481bacc 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;
--
2.39.5
More information about the pbs-devel
mailing list