From 67039da41500deeee6d518706048e748fbc16777 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 2 Aug 2022 15:21:25 +1000 Subject: [PATCH 1/4] fix(#1480): break symlink cycle on find-file --- lua/nvim-tree/actions/finders/find-file.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/nvim-tree/actions/finders/find-file.lua b/lua/nvim-tree/actions/finders/find-file.lua index 6ff67ad1e57..ebffe0b9908 100644 --- a/lua/nvim-tree/actions/finders/find-file.lua +++ b/lua/nvim-tree/actions/finders/find-file.lua @@ -33,10 +33,7 @@ function M.fn(fname) end) :applier(function(node) line = line + 1 - local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator) - local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator) - - if abs_match or link_match then + if vim.startswith(fname_real, node.absolute_path .. utils.path_separator) then node.open = true if #node.nodes == 0 then core.get_explorer():expand(node) From c9ab9bc6c937b4c5e33008f797eaaa8d4d0df292 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 2 Aug 2022 15:42:12 +1000 Subject: [PATCH 2/4] fix(#1480): break symlink cycle on search-node --- lua/nvim-tree/actions/finders/search-node.lua | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/lua/nvim-tree/actions/finders/search-node.lua b/lua/nvim-tree/actions/finders/search-node.lua index 94f8426874d..87ba6920b95 100644 --- a/lua/nvim-tree/actions/finders/search-node.lua +++ b/lua/nvim-tree/actions/finders/search-node.lua @@ -7,42 +7,54 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn local M = {} -local function search(dir, input_path) - local path, name, stat, handle, _ +local function search(search_dir, search_input_path) + local realpaths = {} - if not dir then + if not search_dir then return end - handle, _ = uv.fs_scandir(dir) - if not handle then - return - end + local function iter(dir, input_path) + local realpath, path, name, stat, handle, _ - name, _ = uv.fs_scandir_next(handle) - while name do - path = dir .. "/" .. name + handle, _ = uv.fs_scandir(dir) + if not handle then + return + end - stat, _ = uv.fs_stat(path) - if not stat then - break + realpath, _ = uv.fs_realpath(dir) + if not realpath or vim.tbl_contains(realpaths, realpath) then + return end + table.insert(realpaths, realpath) + + name, _ = uv.fs_scandir_next(handle) + while name do + path = dir .. "/" .. name - if not filters.should_ignore(path) then - if string.find(path, "/" .. input_path .. "$") then - return path + stat, _ = uv.fs_stat(path) + if not stat then + break end - if stat.type == "directory" then - path = search(path, input_path) - if path then + if not filters.should_ignore(path) then + if string.find(path, "/" .. input_path .. "$") then return path end + + if stat.type == "directory" then + path = iter(path, input_path) + if path then + return path + end + end end - end - name, _ = uv.fs_scandir_next(handle) + name, _ = uv.fs_scandir_next(handle) + end end + + return iter(search_dir, search_input_path) end function M.fn() From ef47133b43770ee9bbea53fc66d3640d8b41c44e Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Tue, 2 Aug 2022 16:19:34 +1000 Subject: [PATCH 3/4] fix(#1480): break symlink cycle on search-node --- lua/nvim-tree/actions/finders/search-node.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree/actions/finders/search-node.lua b/lua/nvim-tree/actions/finders/search-node.lua index 87ba6920b95..2252cde96f3 100644 --- a/lua/nvim-tree/actions/finders/search-node.lua +++ b/lua/nvim-tree/actions/finders/search-node.lua @@ -7,14 +7,14 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn local M = {} -local function search(search_dir, search_input_path) +local function search(search_dir, input_path) local realpaths = {} if not search_dir then return end - local function iter(dir, input_path) + local function iter(dir) local realpath, path, name, stat, handle, _ handle, _ = uv.fs_scandir(dir) @@ -54,7 +54,7 @@ local function search(search_dir, search_input_path) end end - return iter(search_dir, search_input_path) + return iter(search_dir) end function M.fn() From e127a991164de485d742259edacc0ce1b186b82d Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 8 Aug 2022 12:27:39 +1000 Subject: [PATCH 4/4] fix(#1480): break symlink cycle on find-file --- lua/nvim-tree/actions/finders/find-file.lua | 13 ++++++++++++- lua/nvim-tree/actions/finders/search-node.lua | 8 ++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree/actions/finders/find-file.lua b/lua/nvim-tree/actions/finders/find-file.lua index ebffe0b9908..df55c1551f2 100644 --- a/lua/nvim-tree/actions/finders/find-file.lua +++ b/lua/nvim-tree/actions/finders/find-file.lua @@ -27,13 +27,24 @@ function M.fn(fname) local line = core.get_nodes_starting_line() + local absolute_paths_searched = {} + local found = Iterator.builder(core.get_explorer().nodes) :matcher(function(node) return node.absolute_path == fname_real or node.link_to == fname_real end) :applier(function(node) line = line + 1 - if vim.startswith(fname_real, node.absolute_path .. utils.path_separator) then + + if vim.tbl_contains(absolute_paths_searched, node.absolute_path) then + return + end + table.insert(absolute_paths_searched, node.absolute_path) + + local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator) + local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator) + + if abs_match or link_match then node.open = true if #node.nodes == 0 then core.get_explorer():expand(node) diff --git a/lua/nvim-tree/actions/finders/search-node.lua b/lua/nvim-tree/actions/finders/search-node.lua index 2252cde96f3..d0b0162cddf 100644 --- a/lua/nvim-tree/actions/finders/search-node.lua +++ b/lua/nvim-tree/actions/finders/search-node.lua @@ -8,7 +8,7 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn local M = {} local function search(search_dir, input_path) - local realpaths = {} + local realpaths_searched = {} if not search_dir then return @@ -23,10 +23,10 @@ local function search(search_dir, input_path) end realpath, _ = uv.fs_realpath(dir) - if not realpath or vim.tbl_contains(realpaths, realpath) then + if not realpath or vim.tbl_contains(realpaths_searched, realpath) then return end - table.insert(realpaths, realpath) + table.insert(realpaths_searched, realpath) name, _ = uv.fs_scandir_next(handle) while name do @@ -43,7 +43,7 @@ local function search(search_dir, input_path) end if stat.type == "directory" then - path = iter(path, input_path) + path = iter(path) if path then return path end