use std::collections::HashSet;
use time::OffsetDateTime;
use super::{DirectoryEntryHeader, PosixAttributes, PosixFileMode, PosixTimestamp, SuspExtension};
#[derive(Clone, Debug, Default, PartialEq)]
pub struct ExtraMeta {
pub alt_name: Option<String>,
pub attributes: Option<PosixAttributes>,
pub symlink_target: Option<String>,
pub extensions: HashSet<SuspExtension>,
pub timestamps: PosixTimestamp,
pub relocated: bool,
}
pub trait ExtraAttributes {
fn ext(&self) -> &ExtraMeta;
fn header(&self) -> &DirectoryEntryHeader;
fn relocated(&self) -> bool {
self.ext().relocated
}
fn time(&self) -> OffsetDateTime {
self.header().time
}
fn owner(&self) -> Option<u32> {
self.ext()
.attributes
.as_ref()
.map(|attributes| attributes.uid)
}
fn group(&self) -> Option<u32> {
self.ext()
.attributes
.as_ref()
.map(|attributes| attributes.gid)
}
fn mode(&self) -> Option<PosixFileMode> {
self.ext()
.attributes
.as_ref()
.map(|attributes| attributes.mode)
}
fn access_time(&self) -> OffsetDateTime {
self.ext().timestamps.access.unwrap_or(self.time())
}
fn attribute_change_time(&self) -> OffsetDateTime {
self.ext().timestamps.attributes.unwrap_or(self.time())
}
fn backup_time(&self) -> OffsetDateTime {
self.ext().timestamps.backup.unwrap_or(self.time())
}
fn create_time(&self) -> OffsetDateTime {
self.ext().timestamps.creation.unwrap_or(self.time())
}
fn effective_time(&self) -> OffsetDateTime {
self.ext().timestamps.effective.unwrap_or(self.time())
}
fn expire_time(&self) -> OffsetDateTime {
self.ext().timestamps.expiration.unwrap_or(self.time())
}
fn modify_time(&self) -> OffsetDateTime {
self.ext().timestamps.modify.unwrap_or(self.time())
}
fn inode(&self) -> Option<u32> {
if let Some(attributes) = &self.ext().attributes {
if let Some(inode) = attributes.inode {
return Some(inode);
}
}
None
}
}