pub use crate::types::*;
pub use std::collections::HashMap;
use std::hash::Hash;
#[derive(Serialize, Deserialize, Debug, Eq, Clone, Hash, PartialEq)]
pub struct Xattr(pub String, pub String, pub i64);
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Eq, Hash)]
pub struct FileObject {
pub rel_path: String,
pub ftype: FileType,
pub xattrs: Vec<Xattr>,
pub fd_index: i64,
}
impl FileObject {
pub fn new(path: &str, ftype: FileType, fd_index: i64) -> Self {
Self {
rel_path: String::from(path),
ftype,
xattrs: Vec::<Xattr>::new(),
fd_index,
}
}
}
impl fmt::Display for FileObject {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut output = format!("Path {}\n Type: ", self.rel_path);
let ftype = match self.ftype {
FileType::Symlink => String::from("symlink"),
FileType::File => String::from("file"),
FileType::Dir => String::from("dir"),
FileType::Fifo => String::from("fifo"),
_ => String::from("other"),
};
output.push_str(&ftype);
output.push_str("\nXattrs:\n");
for xattr in self.xattrs.iter() {
output.push_str(&format!("\t{}:{}\n", xattr.0, xattr.1));
}
write!(f, "{}\n", output)
}
}