use super::ino::Ino; use crate::server::blobref::BlobRef; use fuser::{FileAttr, FileType}; use std::{ ffi::{OsStr, OsString}, time::SystemTime, }; const DEFAULT_PERMISSIONS: u16 = 0o644; #[derive(Debug)] pub struct File { // Files only have a blobref if they were written to. No blob is created if the // files is only `touch`ed. This means empty files will disappear on `umount`. pub blobref: Option, parent: Option, pub attr: FileAttr, name: OsString, } impl File { fn new(ino: Ino, name: &OsStr, kind: FileType) -> Self { let now = SystemTime::now(); let attr = FileAttr { ino: ino.into(), size: 0, blocks: 0, atime: now, mtime: now, ctime: now, crtime: now, kind, perm: DEFAULT_PERMISSIONS, nlink: 0, uid: 0, gid: 0, rdev: 0, flags: 0, blksize: 0, }; File { blobref: None, parent: None, attr, name: name.into(), } } pub fn new_regular_file>(ino: Ino, name: T) -> Self { Self::new(ino, &name.into(), FileType::RegularFile) } pub fn new_directory>(ino: Ino, name: T) -> Self { Self::new(ino, &name.into(), FileType::Directory) } pub fn set_parent(&mut self, ino: Ino) { self.parent = Some(ino); } pub fn name(&self) -> OsString { self.name.clone() } pub fn parent(&self) -> Option { self.parent } pub fn ino(&self) -> Ino { self.attr.ino.into() } pub fn size(&self) -> usize { self.attr.size as usize } }