diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp index bc0c6f4156..160a090ec4 100644 --- a/Userland/Libraries/LibGUI/FileSystemModel.cpp +++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp @@ -261,10 +261,28 @@ FileSystemModel::FileSystemModel(String root_path, Mode mode) dbgln("Event at \"{}\" on Node {}: {}", node.full_path(), &node, event); // FIXME: Your time is coming, un-granular updates. - node.has_traversed = false; - node.mode = 0; - node.children.clear(); - node.reify_if_needed(); + auto refresh_node = [](Node& node) { + node.has_traversed = false; + node.mode = 0; + node.children.clear(); + node.reify_if_needed(); + }; + + if (event.type == Core::FileWatcherEvent::Type::Deleted) { + auto canonical_event_path = LexicalPath::canonicalized_path(event.event_path); + if (m_root_path.starts_with(canonical_event_path)) { + // Deleted directory contains our root, so navigate to our nearest parent. + auto new_path = LexicalPath(m_root_path).dirname(); + while (!Core::File::is_directory(new_path)) + new_path = LexicalPath(new_path).dirname(); + + set_root_path(new_path); + } else if (node.parent) { + refresh_node(*node.parent); + } + } else { + refresh_node(node); + } did_update(); };