Skip to content

Commit e127a99

Browse files
committed
fix(#1480): break symlink cycle on find-file
1 parent bb5cbc8 commit e127a99

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lua/nvim-tree/actions/finders/find-file.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,24 @@ function M.fn(fname)
2727

2828
local line = core.get_nodes_starting_line()
2929

30+
local absolute_paths_searched = {}
31+
3032
local found = Iterator.builder(core.get_explorer().nodes)
3133
:matcher(function(node)
3234
return node.absolute_path == fname_real or node.link_to == fname_real
3335
end)
3436
:applier(function(node)
3537
line = line + 1
36-
if vim.startswith(fname_real, node.absolute_path .. utils.path_separator) then
38+
39+
if vim.tbl_contains(absolute_paths_searched, node.absolute_path) then
40+
return
41+
end
42+
table.insert(absolute_paths_searched, node.absolute_path)
43+
44+
local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator)
45+
local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator)
46+
47+
if abs_match or link_match then
3748
node.open = true
3849
if #node.nodes == 0 then
3950
core.get_explorer():expand(node)

lua/nvim-tree/actions/finders/search-node.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn
88
local M = {}
99

1010
local function search(search_dir, input_path)
11-
local realpaths = {}
11+
local realpaths_searched = {}
1212

1313
if not search_dir then
1414
return
@@ -23,10 +23,10 @@ local function search(search_dir, input_path)
2323
end
2424

2525
realpath, _ = uv.fs_realpath(dir)
26-
if not realpath or vim.tbl_contains(realpaths, realpath) then
26+
if not realpath or vim.tbl_contains(realpaths_searched, realpath) then
2727
return
2828
end
29-
table.insert(realpaths, realpath)
29+
table.insert(realpaths_searched, realpath)
3030

3131
name, _ = uv.fs_scandir_next(handle)
3232
while name do
@@ -43,7 +43,7 @@ local function search(search_dir, input_path)
4343
end
4444

4545
if stat.type == "directory" then
46-
path = iter(path, input_path)
46+
path = iter(path)
4747
if path then
4848
return path
4949
end

0 commit comments

Comments
 (0)