Skip to content

Commit ff1296b

Browse files
committed
fix sshfs compatibility with symlinks
1 parent fe2d3ad commit ff1296b

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

lua/nvim-tree/explorer/init.lua

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function Explorer:reload(node, git_status)
132132

133133
local abs = utils.path_join { cwd, name }
134134
---@type uv.fs_stat.result|nil
135-
local stat = vim.loop.fs_stat(abs)
135+
local stat = vim.loop.fs_lstat(abs)
136136

137137
local filter_reason = self.filters:should_filter_as_reason(abs, stat, filter_status)
138138
if filter_reason == FILTER_REASON.none then
@@ -241,17 +241,17 @@ function Explorer:refresh_parent_nodes_for_path(path)
241241
-- collect parent nodes from the top down
242242
local parent_nodes = {}
243243
NodeIterator.builder({ self })
244-
:recursor(function(node)
245-
return node.nodes
246-
end)
247-
:applier(function(node)
248-
local abs_contains = node.absolute_path and path:find(node.absolute_path, 1, true) == 1
249-
local link_contains = node.link_to and path:find(node.link_to, 1, true) == 1
250-
if abs_contains or link_contains then
251-
table.insert(parent_nodes, node)
252-
end
253-
end)
254-
:iterate()
244+
:recursor(function(node)
245+
return node.nodes
246+
end)
247+
:applier(function(node)
248+
local abs_contains = node.absolute_path and path:find(node.absolute_path, 1, true) == 1
249+
local link_contains = node.link_to and path:find(node.link_to, 1, true) == 1
250+
if abs_contains or link_contains then
251+
table.insert(parent_nodes, node)
252+
end
253+
end)
254+
:iterate()
255255

256256
-- refresh in order; this will expand groups as needed
257257
for _, node in ipairs(parent_nodes) do
@@ -354,7 +354,7 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent)
354354
})
355355

356356
while true do
357-
local name, t = vim.loop.fs_scandir_next(handle)
357+
local name, _ = vim.loop.fs_scandir_next(handle)
358358
if not name then
359359
break
360360
end
@@ -365,15 +365,17 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent)
365365
local profile = log.profile_start("populate_children %s", abs)
366366

367367
---@type uv.fs_stat.result|nil
368-
local stat = vim.loop.fs_stat(abs)
368+
local stat = vim.loop.fs_lstat(abs)
369369
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
370370
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
371+
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
372+
local type = stat and stat.type or nil
371373
local child = nil
372-
if t == "directory" and vim.loop.fs_access(abs, "R") then
374+
if type == "directory" and vim.loop.fs_access(abs, "R") then
373375
child = builders.folder(node, abs, name, stat)
374-
elseif t == "file" then
376+
elseif type == "file" then
375377
child = builders.file(node, abs, name, stat)
376-
elseif t == "link" then
378+
elseif type == "link" then
377379
local link = builders.link(node, abs, name, stat)
378380
if link.link_to ~= nil then
379381
child = link
@@ -437,16 +439,16 @@ end
437439
---@param projects table
438440
function Explorer:refresh_nodes(projects)
439441
Iterator.builder({ self })
440-
:applier(function(n)
441-
if n.nodes then
442-
local toplevel = git.get_toplevel(n.cwd or n.link_to or n.absolute_path)
443-
self:reload(n, projects[toplevel] or {})
444-
end
445-
end)
446-
:recursor(function(n)
447-
return n.group_next and { n.group_next } or (n.open and n.nodes)
448-
end)
449-
:iterate()
442+
:applier(function(n)
443+
if n.nodes then
444+
local toplevel = git.get_toplevel(n.cwd or n.link_to or n.absolute_path)
445+
self:reload(n, projects[toplevel] or {})
446+
end
447+
end)
448+
:recursor(function(n)
449+
return n.group_next and { n.group_next } or (n.open and n.nodes)
450+
end)
451+
:iterate()
450452
end
451453

452454
local event_running = false

0 commit comments

Comments
 (0)