From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pbs-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 1F7461FF15C
	for <inbox@lore.proxmox.com>; Wed,  7 Aug 2024 11:22:58 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id C009B325F;
	Wed,  7 Aug 2024 11:23:07 +0200 (CEST)
MIME-Version: 1.0
In-Reply-To: <20240722103034.343303-4-c.ebner@proxmox.com>
References: <20240722103034.343303-1-c.ebner@proxmox.com>
 <20240722103034.343303-4-c.ebner@proxmox.com>
From: Fabian =?utf-8?q?Gr=C3=BCnbichler?= <f.gruenbichler@proxmox.com>
To: Christian Ebner <c.ebner@proxmox.com>, pbs-devel@lists.proxmox.com
Date: Wed, 07 Aug 2024 11:22:27 +0200
Message-ID: <172302254752.107519.7257401531086504004@yuna.proxmox.com>
User-Agent: alot/0.10
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.048 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
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [proxmox.com, mod.rs]
Subject: Re: [pbs-devel] [PATCH v2 proxmox-backup 3/7] 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
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Backup Server development discussion
 <pbs-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pbs-devel-bounces@lists.proxmox.com
Sender: "pbs-devel" <pbs-devel-bounces@lists.proxmox.com>

Quoting Christian Ebner (2024-07-22 12:30:30)
> Create a dedicated helper for performing the mapping of pxar
> `FileEntry`s to `DirEntryAttribute`s.
> 
> Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
> ---
> changes since version 1:
> - not present in previous version
> 
>  pbs-client/src/tools/mod.rs | 56 +++++++++++++++++++++++--------------
>  1 file changed, 35 insertions(+), 21 deletions(-)
> 
> diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs
> index e6e548403..97f71f3f1 100644
> --- a/pbs-client/src/tools/mod.rs
> +++ b/pbs-client/src/tools/mod.rs
> @@ -720,27 +720,9 @@ pub async fn pxar_metadata_catalog_lookup<T: Clone + ReadAt>(
>          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 map_to_dir_entry_attr(&entry)? {
> +                Some(attr) => attr,
> +                None => continue,
>              };
>  
>              let entry_path = entry_path_with_prefix(&entry, path_prefix.unwrap_or_default());
> @@ -792,3 +774,35 @@ fn entry_path_with_prefix<T: Clone + ReadAt>(entry: &FileEntry<T>, path_prefix:
>      }
>      entry_path
>  }
> +
> +/// Map a pxar [`FileEntry`] to the corresponding [`DirEntryAttribute`].
> +///
> +/// Returns `Ok(None)` if there is no corresponding variant, `Err` if an unknown device type is
> +/// encountered.
> +pub(crate) fn map_to_dir_entry_attr<T: Clone + ReadAt>(

this could live as a TryFrom<pxar::Kind> in DirEntryAttribute?

> +    entry: &FileEntry<T>,
> +) -> Result<Option<DirEntryAttribute>, Error> {
> +    let attr = match entry.kind() {
> +        EntryKind::Version(_) | EntryKind::Prelude(_) | EntryKind::GoodbyeTable => return Ok(None),

provided this can be turned into an error as well, since mapping these entries
to a DirEntryAttribute doesn't make any sense?

AFAICT the existing call sites:
- bail if this returns None
- unwrap the Result and Option(!)
- continue if None (but that one is when iterating over a directory's entries,
  so shouldn't ever hit a Version or Prelude at least)
- don't handle None (when dumping an entry), that should be fine as well

> +        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(Some(attr))
> +}
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
> 
>


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel