From 553f072f9eb85685023c67e3a5479429e24f5022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sun, 14 Jul 2024 22:20:44 -0400 Subject: [PATCH] Fix path cache `.remove_file` and `.remove_dir` implementations --- crates/filesystem/src/path_cache.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/filesystem/src/path_cache.rs b/crates/filesystem/src/path_cache.rs index a5708874..5fb661a4 100644 --- a/crates/filesystem/src/path_cache.rs +++ b/crates/filesystem/src/path_cache.rs @@ -465,8 +465,13 @@ where self.fs.remove_dir(&path).wrap_err_with(|| c.clone())?; + // Remove the directory and its contents from `cache.trie` and `cache.cactus` { let cache = &mut *cache; + + let mut path = to_lowercase(path); + path.set_extension(""); + for extension_trie in cache.trie.iter_prefix(&path).unwrap().map(|(_, t)| t) { for index in extension_trie.values().copied() { cache.cactus.remove(index); @@ -490,14 +495,19 @@ where self.fs.remove_file(&path).wrap_err_with(|| c.clone())?; + // Remove the file from `cache.trie` and `cache.cactus` { let cache = &mut *cache; - for extension_trie in cache.trie.iter_prefix(&path).unwrap().map(|(_, t)| t) { - for index in extension_trie.values().copied() { - cache.cactus.remove(index); - } + + let mut path = to_lowercase(path); + path.set_extension(""); + let path = with_trie_suffix(&path); + + let extension_trie = cache.trie.get_file(&path).unwrap(); + for index in extension_trie.values().copied() { + cache.cactus.remove(index); } - cache.trie.remove_dir(&path); + cache.trie.remove_file(&path); } Ok(())