Skip to content

fix(#1480): break symlink cycle on find-file, search-node #1482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lua/nvim-tree/actions/finders/find-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,20 @@ 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.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)

Expand Down
54 changes: 33 additions & 21 deletions lua/nvim-tree/actions/finders/search-node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, input_path)
local realpaths_searched = {}

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)
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_searched, realpath) then
return
end
table.insert(realpaths_searched, 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)
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)
end

function M.fn()
Expand Down