use crate::alluse::*;
#[derive(Clone, Debug)]
pub struct File {
pub path: Vec<u8>,
pub symlink: Option<Vec<u8>>,
pub(crate) mode: u32,
pub size: u64,
pub mtime: Option<DateTime<Utc>>,
pub(crate) idx: usize,
pub(crate) client_id: usize,
}
impl File {
pub fn unix_mode(&self) -> u32 {
self.mode
}
pub fn is_file(&self) -> bool {
unix_mode::is_file(self.mode)
}
pub fn is_directory(&self) -> bool {
unix_mode::is_dir(self.mode)
}
pub fn is_symlink(&self) -> bool {
unix_mode::is_symlink(self.mode)
}
}
impl std::fmt::Display for File {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(
fmt,
"{} {:>12} {} {}{}",
unix_mode::to_string(self.mode),
self.size,
self.mtime
.as_ref()
.map(DateTime::to_rfc3339)
.unwrap_or(" ".to_owned()),
String::from_utf8_lossy(&self.path),
self.symlink
.as_ref()
.map(|s| format!(" -> {}", String::from_utf8_lossy(&s)))
.unwrap_or("".to_owned())
)?;
Ok(())
}
}
pub struct FileEntryStatus(pub u8);
impl FileEntryStatus {
pub fn is_end(&self) -> bool {
self.0 == 0
}
#[allow(dead_code)] pub fn is_top_level(&self) -> bool {
self.0 & 0x01 != 0
}
pub fn file_mode_repeated(&self) -> bool {
self.0 & 0x02 != 0
}
pub fn uid_repeated(&self) -> bool {
self.0 & 0x08 != 0
}
pub fn gid_repeated(&self) -> bool {
self.0 & 0x10 != 0
}
pub fn inherits_filename(&self) -> bool {
self.0 & 0x20 != 0
}
pub fn integer_filename_len(&self) -> bool {
self.0 & 0x40 != 0
}
pub fn mtime_repeated(&self) -> bool {
self.0 & 0x80 != 0
}
}