[pbs-devel] [PATCH v2 proxmox-backup 3/7] client: tools: factor out pxar entry to dir entry mapping

Christian Ebner c.ebner at proxmox.com
Thu Aug 8 15:36:52 CEST 2024


On 8/7/24 11:22, Fabian Grünbichler wrote:
> 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 at 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?
> 

That will not work, as to convert the entries, not just the kind but 
also their metadata is required.
But will go the suggested route and add this as `TryFrom<&FileEntry<T>>` 
instead, which contains all of what is needed.




More information about the pbs-devel mailing list