From 4222bb875d86a2a53069c75c4833e27f58e26d90 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 14 Feb 2023 15:08:41 +1100 Subject: [PATCH] fix(#1961): cycle detection on refresh, preventing infinite loop (#1996) * #1961 diagnostic logging refresh_nodes_for_path * #1961 add cycle detection to refresh_nodes_for_path * #1961 escape special characters on when path matching during refresh * #1961 escape special characters on when path matching during refresh --- lua/nvim-tree/explorer/reload.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree/explorer/reload.lua b/lua/nvim-tree/explorer/reload.lua index 77386415853..89fdf5ff1f9 100644 --- a/lua/nvim-tree/explorer/reload.lua +++ b/lua/nvim-tree/explorer/reload.lua @@ -166,6 +166,9 @@ function M.refresh_nodes_for_path(path) local profile = log.profile_start("refresh_nodes_for_path %s", path) + -- avoids cycles + local paths_refreshed = {} + NodeIterator.builder({ explorer }) :hidden() :recursor(function(node) @@ -177,10 +180,13 @@ function M.refresh_nodes_for_path(path) end end) :applier(function(node) - local abs_contains = node.absolute_path and path:match("^" .. node.absolute_path) - local link_contains = node.link_to and path:match("^" .. node.link_to) + local abs_contains = node.absolute_path and path:find(node.absolute_path, 1, true) ~= 1 + local link_contains = node.link_to and path:find(node.link_to, 1, true) ~= 1 if abs_contains or link_contains then - M.refresh_node(node) + if not paths_refreshed[node.absolute_path] then + paths_refreshed[node.absolute_path] = true + M.refresh_node(node) + end end end) :iterate()