From b88e384f9535f84ca782fe0eace1359542c4cca3 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sun, 12 Jun 2022 19:17:06 +1000 Subject: [PATCH] Fix `Vfs::add_path`: Add insert `filename` instead of `path` into the `HashSet>` Signed-off-by: Jiahao XU --- src/drivers/vfs.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/drivers/vfs.rs b/src/drivers/vfs.rs index 08178b06..d43b3a8a 100644 --- a/src/drivers/vfs.rs +++ b/src/drivers/vfs.rs @@ -17,11 +17,14 @@ impl Vfs { /// * `path` - must be canonical, must not be empty. pub(super) fn add_path(&mut self, mut path: &Path) { while let Some(parent) = path.parent() { - if let Some(path_str) = path.to_str() { + // Since path has parent, it must have a filename + let filename = path.file_name().unwrap(); + + if let Some(filename) = filename.to_str() { self.0 .entry(parent.into()) .or_insert_with(|| HashSet::with_capacity(4)) - .insert(path_str.into()); + .insert(filename.into()); } path = parent;