From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 648661FF15F for ; Mon, 12 Aug 2024 12:32:15 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5D7A73079F; Mon, 12 Aug 2024 12:32:29 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 12 Aug 2024 12:31:35 +0200 Message-Id: <20240812103139.288854-7-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240812103139.288854-1-c.ebner@proxmox.com> References: <20240812103139.288854-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pbs-devel] [PATCH v3 proxmox-backup 06/10] client: tools: factor out pxar entry to dir entry mapping X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Perform the conversion from pxar file entries to catalog entry attributes by implementing `TryFrom<&FileEntry>` for `DirEntryAttribute` and use that. Allows the reuse for the catalog shell, when using the split pxar archive instead of the catalog. Signed-off-by: Christian Ebner --- changes since version 2: - implement `TryFrom<&FileEntry>` for `DirEntryAttribute` conversion instead of a helper. pbs-client/src/pxar/tools.rs | 26 ++++------------------- pbs-datastore/src/catalog.rs | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/pbs-client/src/pxar/tools.rs b/pbs-client/src/pxar/tools.rs index 25500f748..68207cd31 100644 --- a/pbs-client/src/pxar/tools.rs +++ b/pbs-client/src/pxar/tools.rs @@ -299,30 +299,12 @@ pub async fn pxar_metadata_catalog_lookup( while let Some(entry) = entries_iter.next().await { let entry = entry?.decode_entry().await?; - let entry_attr = match entry.kind() { - EntryKind::Version(_) | EntryKind::Prelude(_) | EntryKind::GoodbyeTable => continue, - EntryKind::Directory => DirEntryAttribute::Directory { - start: entry.entry_range_info().entry_range.start, - }, - EntryKind::File { size, .. } => { - let mtime = match entry.metadata().mtime_as_duration() { - SignedDuration::Positive(val) => i64::try_from(val.as_secs())?, - SignedDuration::Negative(val) => -i64::try_from(val.as_secs())?, - }; - DirEntryAttribute::File { size: *size, mtime } - } - EntryKind::Device(_) => match entry.metadata().file_type() { - mode::IFBLK => DirEntryAttribute::BlockDevice, - mode::IFCHR => DirEntryAttribute::CharDevice, - _ => bail!("encountered unknown device type"), - }, - EntryKind::Symlink(_) => DirEntryAttribute::Symlink, - EntryKind::Hardlink(_) => DirEntryAttribute::Hardlink, - EntryKind::Fifo => DirEntryAttribute::Fifo, - EntryKind::Socket => DirEntryAttribute::Socket, + let entry_attr = match DirEntryAttribute::try_from(&entry) { + Ok(attr) => attr, + Err(_) => continue, }; - let entry_path = entry_path_with_prefix(&entry, path_prefix); + let entry_path = crate::pxar::tools::entry_path_with_prefix(&entry, path_prefix); entries.push(ArchiveEntry::new( entry_path.as_os_str().as_bytes(), Some(&entry_attr), diff --git a/pbs-datastore/src/catalog.rs b/pbs-datastore/src/catalog.rs index eb5318370..f0589f888 100644 --- a/pbs-datastore/src/catalog.rs +++ b/pbs-datastore/src/catalog.rs @@ -7,6 +7,10 @@ use anyhow::{bail, format_err, Error}; use serde::{Deserialize, Serialize}; use pathpatterns::{MatchList, MatchType}; +use pxar::accessor::aio::FileEntry; +use pxar::accessor::ReadAt; +use pxar::format::SignedDuration; +use pxar::{mode, EntryKind}; use proxmox_io::ReadExt; use proxmox_schema::api; @@ -104,6 +108,42 @@ pub enum DirEntryAttribute { Socket, } +impl TryFrom<&FileEntry> for DirEntryAttribute +where + T: Clone + ReadAt, +{ + type Error = Error; + + fn try_from(entry: &FileEntry) -> Result { + let attr = match entry.kind() { + EntryKind::Version(_) | EntryKind::Prelude(_) | EntryKind::GoodbyeTable => bail!( + "cannot convert pxar entry kind {:?} to catalog directory entry attribute", + entry.kind(), + ), + EntryKind::Directory => DirEntryAttribute::Directory { + start: entry.entry_range_info().entry_range.start, + }, + EntryKind::File { size, .. } => { + let mtime = match entry.metadata().mtime_as_duration() { + SignedDuration::Positive(val) => i64::try_from(val.as_secs())?, + SignedDuration::Negative(val) => -i64::try_from(val.as_secs())?, + }; + DirEntryAttribute::File { size: *size, mtime } + } + EntryKind::Device(_) => match entry.metadata().file_type() { + mode::IFBLK => DirEntryAttribute::BlockDevice, + mode::IFCHR => DirEntryAttribute::CharDevice, + _ => bail!("encountered unknown device type"), + }, + EntryKind::Symlink(_) => DirEntryAttribute::Symlink, + EntryKind::Hardlink(_) => DirEntryAttribute::Hardlink, + EntryKind::Fifo => DirEntryAttribute::Fifo, + EntryKind::Socket => DirEntryAttribute::Socket, + }; + Ok(attr) + } +} + impl DirEntry { fn new(etype: CatalogEntryType, name: Vec, start: u64, size: u64, mtime: i64) -> Self { match etype { -- 2.39.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel