public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Christian Ebner <c.ebner@proxmox.com>, pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH v2 proxmox-backup 3/7] client: tools: factor out pxar entry to dir entry mapping
Date: Wed, 07 Aug 2024 11:22:27 +0200	[thread overview]
Message-ID: <172302254752.107519.7257401531086504004@yuna.proxmox.com> (raw)
In-Reply-To: <20240722103034.343303-4-c.ebner@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


  reply	other threads:[~2024-08-07  9:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-22 10:30 [pbs-devel] [PATCH v2 proxmox-backup 0/7] fix catalog dump and shell for split pxar archives Christian Ebner
2024-07-22 10:30 ` [pbs-devel] [PATCH v2 proxmox-backup 1/7] client: make helper to get remote pxar reader reusable Christian Ebner
2024-07-22 10:30 ` [pbs-devel] [PATCH v2 proxmox-backup 2/7] client: tools: factor out entry path prefix helper Christian Ebner
2024-08-07  9:13   ` Fabian Grünbichler
2024-07-22 10:30 ` [pbs-devel] [PATCH v2 proxmox-backup 3/7] client: tools: factor out pxar entry to dir entry mapping Christian Ebner
2024-08-07  9:22   ` Fabian Grünbichler [this message]
2024-08-08 13:36     ` Christian Ebner
2024-07-22 10:30 ` [pbs-devel] [PATCH v2 proxmox-backup 4/7] client: add helper to dump catalog from metadata archive Christian Ebner
2024-07-22 10:30 ` [pbs-devel] [PATCH v2 proxmox-backup 5/7] client: catalog: fallback to metadata archives for catalog dump Christian Ebner
2024-07-22 10:30 ` [pbs-devel] [PATCH v2 proxmox-backup 6/7] client: helper to mimic catalog find using metadata archive Christian Ebner
2024-07-22 10:30 ` [pbs-devel] [PATCH v2 proxmox-backup 7/7] client: catalog shell: fallback to accessor for navigation Christian Ebner
2024-08-07  9:39 ` [pbs-devel] [PATCH v2 proxmox-backup 0/7] fix catalog dump and shell for split pxar archives Fabian Grünbichler
2024-08-12 10:32 ` Christian Ebner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=172302254752.107519.7257401531086504004@yuna.proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=c.ebner@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal