Skip to content

Commit 2d6e64d

Browse files
mxplealex-courtis
andauthored
fix(nvim-tree#2794): sshfs compatibility (nvim-tree#2893)
* add type fallback for nil types * add PR suggestions * Update lua/nvim-tree/explorer/explore.lua Co-authored-by: Alexander Courtis <alex@courtis.org> * use type from fs_stat for sshfs compatibility --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent cb57691 commit 2d6e64d

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

lua/nvim-tree/actions/fs/remove-file.lua

+7-2
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ local function remove_dir(cwd)
5656
end
5757

5858
while true do
59-
local name, t = vim.loop.fs_scandir_next(handle)
59+
local name, _ = vim.loop.fs_scandir_next(handle)
6060
if not name then
6161
break
6262
end
6363

6464
local new_cwd = utils.path_join { cwd, name }
65-
if t == "directory" then
65+
66+
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
67+
local stat = vim.loop.fs_stat(new_cwd)
68+
local type = stat and stat.type or nil
69+
70+
if type == "directory" then
6671
local success = remove_dir(new_cwd)
6772
if not success then
6873
return false

lua/nvim-tree/explorer/explore.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ local function populate_children(handle, cwd, node, git_status, parent)
2929
})
3030

3131
while true do
32-
local name, t = vim.loop.fs_scandir_next(handle)
32+
local name, _ = vim.loop.fs_scandir_next(handle)
3333
if not name then
3434
break
3535
end
@@ -41,14 +41,18 @@ local function populate_children(handle, cwd, node, git_status, parent)
4141

4242
---@type uv.fs_stat.result|nil
4343
local stat = vim.loop.fs_stat(abs)
44+
45+
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
46+
local type = stat and stat.type or nil
47+
4448
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
4549
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then
4650
local child = nil
47-
if t == "directory" and vim.loop.fs_access(abs, "R") then
51+
if type == "directory" and vim.loop.fs_access(abs, "R") then
4852
child = builders.folder(node, abs, name, stat)
49-
elseif t == "file" then
53+
elseif type == "file" then
5054
child = builders.file(node, abs, name, stat)
51-
elseif t == "link" then
55+
elseif type == "link" then
5256
local link = builders.link(node, abs, name, stat)
5357
if link.link_to ~= nil then
5458
child = link

lua/nvim-tree/explorer/init.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function Explorer:reload(node, git_status)
119119
})
120120

121121
while true do
122-
local name, t = vim.loop.fs_scandir_next(handle)
122+
local name, _ = vim.loop.fs_scandir_next(handle)
123123
if not name then
124124
break
125125
end
@@ -132,11 +132,14 @@ function Explorer:reload(node, git_status)
132132
if filter_reason == FILTER_REASON.none then
133133
remain_childs[abs] = true
134134

135+
-- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility
136+
local type = stat and stat.type or nil
137+
135138
-- Recreate node if type changes.
136139
if nodes_by_path[abs] then
137140
local n = nodes_by_path[abs]
138141

139-
if n.type ~= t then
142+
if n.type ~= type then
140143
utils.array_remove(node.nodes, n)
141144
explorer_node.node_destroy(n)
142145
nodes_by_path[abs] = nil
@@ -145,11 +148,11 @@ function Explorer:reload(node, git_status)
145148

146149
if not nodes_by_path[abs] then
147150
local new_child = nil
148-
if t == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then
151+
if type == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then
149152
new_child = builders.folder(node, abs, name, stat)
150-
elseif t == "file" then
153+
elseif type == "file" then
151154
new_child = builders.file(node, abs, name, stat)
152-
elseif t == "link" then
155+
elseif type == "link" then
153156
local link = builders.link(node, abs, name, stat)
154157
if link.link_to ~= nil then
155158
new_child = link

0 commit comments

Comments
 (0)