Fix Vfs::add_path: Add insert filename instead of path

into the `HashSet<Box<Path>>`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-12 19:17:06 +10:00
parent b879c15c70
commit b88e384f95
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -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;