use std::io::Read;
use std::path::Path;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EntryKind {
File,
Directory,
Symlink { target: String },
}
pub struct Entry<'a> {
pub name: String,
pub size: u64,
pub kind: EntryKind,
pub mode: Option<u32>,
pub reader: Box<dyn Read + 'a>,
}
impl<'a> Entry<'a> {
pub fn is_file(&self) -> bool {
matches!(self.kind, EntryKind::File)
}
pub fn is_dir(&self) -> bool {
matches!(self.kind, EntryKind::Directory)
}
pub fn is_symlink(&self) -> bool {
matches!(self.kind, EntryKind::Symlink { .. })
}
pub fn symlink_target(&self) -> Option<&str> {
match &self.kind {
EntryKind::Symlink { target } => Some(target),
_ => None,
}
}
pub fn depth(&self) -> usize {
Path::new(&self.name).components().count()
}
}
#[derive(Debug, Clone)]
pub struct EntryInfo {
pub name: String,
pub size: u64,
pub kind: EntryKind,
pub mode: Option<u32>,
}
impl<'a> From<&Entry<'a>> for EntryInfo {
fn from(entry: &Entry<'a>) -> Self {
Self {
name: entry.name.clone(),
size: entry.size,
kind: entry.kind.clone(),
mode: entry.mode,
}
}
}