diff options
author | edef <edef@unfathomable.blue> | 2022-04-12 22:53:07 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-04-12 22:54:16 +0000 |
commit | 443d5fb95f15552eb73aac7165c969bf84af0648 (patch) | |
tree | d64aeddc8cfa761b7358986a5562c08df2e9cbcc /ripple/fossil/src/bin | |
parent | e02ebdd45f5b66f917bb5dfa92605eab7b02044d (diff) | |
download | unf-legacy-443d5fb95f15552eb73aac7165c969bf84af0648.tar.zst |
ripple/fossil/mount: outline node handling logic from file_attr callers
Change-Id: I162b542d31a8120792e72957e6ffaf1bd94d9676
Diffstat (limited to 'ripple/fossil/src/bin')
-rw-r--r-- | ripple/fossil/src/bin/mount.rs | 52 |
1 files changed, 14 insertions, 38 deletions
diff --git a/ripple/fossil/src/bin/mount.rs b/ripple/fossil/src/bin/mount.rs index 75698a5..2f96a9c 100644 --- a/ripple/fossil/src/bin/mount.rs +++ b/ripple/fossil/src/bin/mount.rs @@ -17,13 +17,13 @@ lazy_static! { static ref EPOCH_PLUS_ONE: SystemTime = UNIX_EPOCH + Duration::from_secs(1); } -enum Kind { - Link, - File, - Directory, -} +fn file_attr(ino: u64, node: &memtree::Node) -> fuser::FileAttr { + let size = match node { + memtree::Node::Directory(d) => d.len() as u64, + memtree::Node::File(f) => f.size as u64, + memtree::Node::Link { target } => target.len() as u64, + }; -fn file_attr(ino: u64, kind: Kind, size: u64) -> fuser::FileAttr { let blksize = 512; fuser::FileAttr { /// Inode number @@ -42,14 +42,14 @@ fn file_attr(ino: u64, kind: Kind, size: u64) -> fuser::FileAttr { /// Time of creation (macOS only) crtime: *EPOCH_PLUS_ONE, /// Kind of file (directory, file, pipe, etc) - kind: match kind { - Kind::Directory => fuser::FileType::Directory, - Kind::File => fuser::FileType::RegularFile, - Kind::Link => fuser::FileType::Symlink, + kind: match node { + memtree::Node::Directory(_) => fuser::FileType::Directory, + memtree::Node::File(_) => fuser::FileType::RegularFile, + memtree::Node::Link {..}=> fuser::FileType::Symlink, }, /// Permissions - perm: match kind { - Kind::Directory => 0o755, + perm: match node{ + memtree::Node::Directory(_) => 0o755, _ => 0o644, }, /// Number of hard links @@ -140,20 +140,8 @@ impl fuser::Filesystem for Filesystem { match entry { None => reply.error(ENOENT), Some((idx, node)) => { - let attr; let ino = parent + idx as u64 + 1; - match node { - memtree::Node::Directory(d) => { - attr = file_attr(ino, Kind::Directory, d.len() as u64); - } - memtree::Node::File(f) => { - attr = file_attr(ino, Kind::File, f.size as u64); - } - memtree::Node::Link { target } => { - attr = file_attr(ino, Kind::Link, target.len() as u64); - } - } - reply.entry(&Duration::ZERO, &attr, 0); + reply.entry(&Duration::ZERO, &file_attr(ino, node), 0); } } } @@ -162,19 +150,7 @@ impl fuser::Filesystem for Filesystem { fn getattr(&mut self, _req: &fuser::Request<'_>, ino: u64, reply: fuser::ReplyAttr) { if let Some(node) = self.find(ino) { - let attr; - match node { - memtree::Node::Directory(d) => { - attr = file_attr(ino, Kind::Directory, d.len() as u64); - } - memtree::Node::File(f) => { - attr = file_attr(ino, Kind::File, f.size as u64); - } - memtree::Node::Link { target } => { - attr = file_attr(ino, Kind::Link, target.len() as u64); - } - } - reply.attr(&Duration::ZERO, &attr); + reply.attr(&Duration::ZERO, &file_attr(ino, node)); } else { reply.error(ENOENT); } |