From 9650e735baad0d39505f4cb4867a60f02858536a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20=E6=9D=8E?= <83033020+mxple@users.noreply.github.com> Date: Sat, 28 Sep 2024 19:21:02 -0400 Subject: [PATCH] fix(#2794): sshfs compatibility (#2922) * Revert "revert(#2794): sshfs compatibility (#2920)" This reverts commit 8405ecfbd6bb08a94ffc9c68fef211eea56e8a3b. Fix for symlinks is simple * fix sshfs compatibility with symlinks * add suggestions * revert variable name change to ease multi-instance feature branch conflicts --------- Co-authored-by: Alexander Courtis --- lua/nvim-tree/actions/fs/remove-file.lua | 9 +++++++-- lua/nvim-tree/explorer/init.lua | 13 +++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index d9b0357c..14a30d3a 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -57,13 +57,18 @@ local function remove_dir(cwd) end while true do - local name, t = vim.loop.fs_scandir_next(handle) + local name, _ = vim.loop.fs_scandir_next(handle) if not name then break end local new_cwd = utils.path_join { cwd, name } - if t == "directory" then + + -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility + local stat = vim.loop.fs_stat(new_cwd) + local type = stat and stat.type or nil + + if type == "directory" then local success = remove_dir(new_cwd) if not success then return false diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index eb899f78..a180bb70 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -125,19 +125,22 @@ function Explorer:reload(node, git_status) }) while true do - local name, t = vim.loop.fs_scandir_next(handle) + local name, _ = vim.loop.fs_scandir_next(handle) if not name then break end local abs = utils.path_join { cwd, name } ---@type uv.fs_stat.result|nil - local stat = vim.loop.fs_stat(abs) + local stat = vim.loop.fs_lstat(abs) local filter_reason = self.filters:should_filter_as_reason(abs, stat, filter_status) if filter_reason == FILTER_REASON.none then remain_childs[abs] = true + -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility + local t = stat and stat.type or nil + -- Recreate node if type changes. if nodes_by_path[abs] then local n = nodes_by_path[abs] @@ -351,7 +354,7 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent) }) while true do - local name, t = vim.loop.fs_scandir_next(handle) + local name, _ = vim.loop.fs_scandir_next(handle) if not name then break end @@ -362,9 +365,11 @@ function Explorer:populate_children(handle, cwd, node, git_status, parent) local profile = log.profile_start("populate_children %s", abs) ---@type uv.fs_stat.result|nil - local stat = vim.loop.fs_stat(abs) + local stat = vim.loop.fs_lstat(abs) local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status) if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] then + -- Type must come from fs_stat and not fs_scandir_next to maintain sshfs compatibility + local t = stat and stat.type or nil local child = nil if t == "directory" and vim.loop.fs_access(abs, "R") then child = builders.folder(node, abs, name, stat)