diff options
author | edef <edef@unfathomable.blue> | 2022-05-03 16:36:25 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-05-03 17:16:19 +0000 |
commit | 6acd605e50d05b026c9db1a3de10cca5d188dc44 (patch) | |
tree | 9439e35ad5e31b0262c634169d0deea947b45e81 /ripple | |
parent | a052f814289d5f1f4751cc50e1d2aef879da43a8 (diff) | |
download | unf-legacy-6acd605e50d05b026c9db1a3de10cca5d188dc44.tar.zst |
ripple/fossil/mount: memtree API cleanup
This replaces the tuples with a DirectoryEntry struct. Change-Id: I42a49fee03f7abfac9143c48106ebeb964814ca9
Diffstat (limited to 'ripple')
-rw-r--r-- | ripple/fossil/src/bin/mount.rs | 38 |
1 files changed, 26 insertions, 12 deletions
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<Item = (&str, u32, &Node)> { + pub fn iter(&self) -> impl Iterator<Item = DirectoryEntry> { 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<DirectoryEntry> { + 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() } } |