add From<&DirEntryAttribute to CatalogEntryType and make it pub(crate)

we want to get a string representation of the DirEntryAttribute
like 'f' for file, etc. and since we have such a mapping already
in the CatalogEntryType, use that

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-06-23 12:09:51 +02:00 committed by Dietmar Maurer
parent e44fe0c9f5
commit 05d18b907a

View File

@ -15,7 +15,7 @@ use crate::pxar::catalog::BackupCatalogWriter;
#[repr(u8)]
#[derive(Copy,Clone,PartialEq)]
enum CatalogEntryType {
pub(crate) enum CatalogEntryType {
Directory = b'd',
File = b'f',
Symlink = b'l',
@ -44,6 +44,21 @@ impl TryFrom<u8> for CatalogEntryType {
}
}
impl From<&DirEntryAttribute> for CatalogEntryType {
fn from(value: &DirEntryAttribute) -> Self {
match value {
DirEntryAttribute::Directory { .. } => CatalogEntryType::Directory,
DirEntryAttribute::File { .. } => CatalogEntryType::File,
DirEntryAttribute::Symlink => CatalogEntryType::Symlink,
DirEntryAttribute::Hardlink => CatalogEntryType::Hardlink,
DirEntryAttribute::BlockDevice => CatalogEntryType::BlockDevice,
DirEntryAttribute::CharDevice => CatalogEntryType::CharDevice,
DirEntryAttribute::Fifo => CatalogEntryType::Fifo,
DirEntryAttribute::Socket => CatalogEntryType::Socket,
}
}
}
impl fmt::Display for CatalogEntryType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", char::from(*self as u8))