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

* fix(#1480): break symlink cycle on find-file

* fix(#1480): break symlink cycle on search-node

* fix(#1480): break symlink cycle on search-node

* fix(#1480): break symlink cycle on find-file
This commit is contained in:
Alexander Courtis
2022-08-08 12:46:09 +10:00
committed by GitHub
parent a73d0d4800
commit 261a5c380c
2 changed files with 45 additions and 25 deletions

View File

@@ -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
stat, _ = uv.fs_stat(path)
if not stat then
break
handle, _ = uv.fs_scandir(dir)
if not handle then
return
end
if not filters.should_ignore(path) then
if string.find(path, "/" .. input_path .. "$") then
return path
end
if stat.type == "directory" then
path = search(path, input_path)
if path then
return path
end
end
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
stat, _ = uv.fs_stat(path)
if not stat then
break
end
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
name, _ = uv.fs_scandir_next(handle)
end
end
return iter(search_dir)
end
function M.fn()