summary refs log tree commit diff
path: root/ripple
diff options
context:
space:
mode:
Diffstat (limited to 'ripple')
-rw-r--r--ripple/fossil/src/bin/mount.rs52
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);
 		}