From b06ebf8f6d7bf88e21fd813cdbd7ca0dfb1ad617 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sun, 18 Aug 2024 16:38:05 +1000 Subject: [PATCH] fix(#2868): windows: do not visit unenumerable directories such as Application Data --- lua/nvim-tree/explorer/explore.lua | 57 ++++++++++++++++-------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/lua/nvim-tree/explorer/explore.lua b/lua/nvim-tree/explorer/explore.lua index 44486ec66c6..da7c1b32e8c 100644 --- a/lua/nvim-tree/explorer/explore.lua +++ b/lua/nvim-tree/explorer/explore.lua @@ -35,37 +35,40 @@ local function populate_children(handle, cwd, node, git_status, parent) end local abs = utils.path_join { cwd, name } - local profile = log.profile_start("explore populate_children %s", abs) - - ---@type uv.fs_stat.result|nil - local stat = vim.loop.fs_stat(abs) - local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status) - if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] and Watcher.is_fs_event_capable(abs) then - local child = nil - if t == "directory" and vim.loop.fs_access(abs, "R") then - child = builders.folder(node, abs, name, stat) - elseif t == "file" then - child = builders.file(node, abs, name, stat) - elseif t == "link" then - local link = builders.link(node, abs, name, stat) - if link.link_to ~= nil then - child = link + + if Watcher.is_fs_event_capable(abs) then + local profile = log.profile_start("explore populate_children %s", abs) + + ---@type uv.fs_stat.result|nil + local stat = vim.loop.fs_stat(abs) + local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status) + if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then + local child = nil + if t == "directory" and vim.loop.fs_access(abs, "R") then + child = builders.folder(node, abs, name, stat) + elseif t == "file" then + child = builders.file(node, abs, name, stat) + elseif t == "link" then + local link = builders.link(node, abs, name, stat) + if link.link_to ~= nil then + child = link + end end - end - if child then - table.insert(node.nodes, child) - nodes_by_path[child.absolute_path] = true - explorer_node.update_git_status(child, node_ignored, git_status) - end - else - for reason, value in pairs(FILTER_REASON) do - if filter_reason == value then - node.hidden_stats[reason] = node.hidden_stats[reason] + 1 + if child then + table.insert(node.nodes, child) + nodes_by_path[child.absolute_path] = true + explorer_node.update_git_status(child, node_ignored, git_status) + end + else + for reason, value in pairs(FILTER_REASON) do + if filter_reason == value then + node.hidden_stats[reason] = node.hidden_stats[reason] + 1 + end end end - end - log.profile_end(profile) + log.profile_end(profile) + end end end