* 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:
committed by
GitHub
parent
a73d0d4800
commit
261a5c380c
@@ -27,12 +27,20 @@ function M.fn(fname)
|
|||||||
|
|
||||||
local line = core.get_nodes_starting_line()
|
local line = core.get_nodes_starting_line()
|
||||||
|
|
||||||
|
local absolute_paths_searched = {}
|
||||||
|
|
||||||
local found = Iterator.builder(core.get_explorer().nodes)
|
local found = Iterator.builder(core.get_explorer().nodes)
|
||||||
:matcher(function(node)
|
:matcher(function(node)
|
||||||
return node.absolute_path == fname_real or node.link_to == fname_real
|
return node.absolute_path == fname_real or node.link_to == fname_real
|
||||||
end)
|
end)
|
||||||
:applier(function(node)
|
:applier(function(node)
|
||||||
line = line + 1
|
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 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)
|
local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator)
|
||||||
|
|
||||||
|
|||||||
@@ -7,42 +7,54 @@ local find_file = require("nvim-tree.actions.finders.find-file").fn
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function search(dir, input_path)
|
local function search(search_dir, input_path)
|
||||||
local path, name, stat, handle, _
|
local realpaths_searched = {}
|
||||||
|
|
||||||
if not dir then
|
if not search_dir then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
handle, _ = uv.fs_scandir(dir)
|
local function iter(dir)
|
||||||
if not handle then
|
local realpath, path, name, stat, handle, _
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
name, _ = uv.fs_scandir_next(handle)
|
handle, _ = uv.fs_scandir(dir)
|
||||||
while name do
|
if not handle then
|
||||||
path = dir .. "/" .. name
|
return
|
||||||
|
|
||||||
stat, _ = uv.fs_stat(path)
|
|
||||||
if not stat then
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not filters.should_ignore(path) then
|
realpath, _ = uv.fs_realpath(dir)
|
||||||
if string.find(path, "/" .. input_path .. "$") then
|
if not realpath or vim.tbl_contains(realpaths_searched, realpath) then
|
||||||
return path
|
return
|
||||||
end
|
|
||||||
|
|
||||||
if stat.type == "directory" then
|
|
||||||
path = search(path, input_path)
|
|
||||||
if path then
|
|
||||||
return path
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
table.insert(realpaths_searched, realpath)
|
||||||
|
|
||||||
name, _ = uv.fs_scandir_next(handle)
|
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
|
end
|
||||||
|
|
||||||
|
return iter(search_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.fn()
|
function M.fn()
|
||||||
|
|||||||
Reference in New Issue
Block a user