From 6acd605e50d05b026c9db1a3de10cca5d188dc44 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 3 May 2022 16:36:25 +0000 Subject: ripple/fossil/mount: memtree API cleanup This replaces the tuples with a DirectoryEntry struct. Change-Id: I42a49fee03f7abfac9143c48106ebeb964814ca9 --- ripple/fossil/src/bin/mount.rs | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'ripple') diff --git a/ripple/fossil/src/bin/mount.rs b/ripple/fossil/src/bin/mount.rs index 0f9e2ec..c43a5ae 100644 --- a/ripple/fossil/src/bin/mount.rs +++ b/ripple/fossil/src/bin/mount.rs @@ -156,9 +156,9 @@ impl fuser::Filesystem for Filesystem { let entry = name.to_str().and_then(|name| dir.lookup(name)); match entry { None => reply.error(ENOENT), - Some((idx, node)) => { - let ino = parent + idx as u64 + 1; - reply.entry(&Duration::ZERO, &file_attr(ino, node), 0); + Some(entry) => { + let ino = parent + entry.index as u64 + 1; + reply.entry(&Duration::ZERO, &file_attr(ino, entry.node), 0); } } } @@ -328,13 +328,13 @@ impl fuser::Filesystem for Filesystem { (ino, fuser::FileType::Directory, ".."), ]; - for (name, idx, node) in dir.iter() { - let kind = match node { + for entry in dir.iter() { + let kind = match entry.node { memtree::Node::Directory(_) => fuser::FileType::Directory, memtree::Node::File(_) => fuser::FileType::RegularFile, memtree::Node::Link { .. } => fuser::FileType::Symlink, }; - children.push((ino + idx as u64 + 1, kind, name)); + children.push((ino + entry.index as u64 + 1, kind, entry.name)); } for (offset, &(ino, kind, name)) in children.iter().enumerate().skip(offset as usize) { @@ -684,20 +684,34 @@ mod memtree { size: u32, } + pub struct DirectoryEntry<'a> { + pub name: &'a str, + pub index: u32, + pub node: &'a Node, + } + impl Directory { - pub fn iter(&self) -> impl Iterator { + pub fn iter(&self) -> impl Iterator { let by_name = self.by_name.iter(); let by_index = self.by_index.iter(); by_name.zip(by_index).map(|((name, &idx), (&idy, node))| { assert_eq!(idx, idy); - (name.as_str(), idx, node) + DirectoryEntry { + name: &name, + index: idx, + node, + } }) } - pub fn lookup(&self, name: &str) -> Option<(u32, &Node)> { - let &idx = self.by_name.get(name)?; - Some((idx, &self.by_index[&idx])) + pub fn lookup<'a>(&self, name: &'a str) -> Option { + let (name, &index) = self.by_name.get_key_value(name)?; + Some(DirectoryEntry { + name, + index, + node: &self.by_index[&index], + }) } } @@ -715,7 +729,7 @@ mod memtree { impl fmt::Debug for DirectoryMembers<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_map() - .entries(self.0.iter().map(|(name, idx, node)| ((name, idx), node))) + .entries(self.0.iter().map(|e| ((e.name, e.index), e.node))) .finish() } } -- cgit 1.4.1