From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 0D2A41FF15F for ; Mon, 21 Oct 2024 17:47:36 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7F8E638108; Mon, 21 Oct 2024 17:48:10 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 21 Oct 2024 17:47:40 +0200 Message-Id: <20241021154744.325556-7-c.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241021154744.325556-1-c.ebner@proxmox.com> References: <20241021154744.325556-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 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 Subject: [pbs-devel] [PATCH v4 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. This is in preparation for implementing the catalog shell, where the same logic will be used to generate the catalog entry attributes. Signed-off-by: Christian Ebner --- changes since version 3: - Adapt commit message to reflect the intent for this patch more clearly 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.5 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel