From 05d18b907a6bc9a9ab94c85c22db0ab84e955ed6 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 23 Jun 2020 12:09:51 +0200 Subject: [PATCH] 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 --- src/backup/catalog.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/backup/catalog.rs b/src/backup/catalog.rs index 9ccff29f..bc2e471e 100644 --- a/src/backup/catalog.rs +++ b/src/backup/catalog.rs @@ -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 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))