Skip to content

Commit 430d70b

Browse files
committed
perf: proper handling around sshfs process and channels
1 parent d3581ed commit 430d70b

4 files changed

Lines changed: 26 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ luac.out
3939
*.x86_64
4040
*.hex
4141

42+
.nvimlog

.nvimlog

Lines changed: 0 additions & 2 deletions
This file was deleted.

lua/remote-sshfs/connections.lua

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ M.mount_host = function(host, mount_dir, ask_pass)
133133
local function start_job()
134134
vim.notify("Connecting to host (" .. remote_host .. ")...")
135135
local skip_clean = false
136-
mount_point = mount_dir .. "/"
137-
current_host = host
138-
-- Spawn SSHFS without a shell
139-
sshfs_job_id = vim.fn.jobstart(cmd, {
136+
local spec_mount_point = mount_dir .. "/"
137+
local spec_host = host
138+
local id = vim.fn.jobstart(cmd, {
140139
on_stdout = function(_, data)
141140
handler.sshfs_wrapper(data, mount_dir, function(event)
142141
if event == "ask_pass" then
@@ -153,18 +152,27 @@ M.mount_host = function(host, mount_dir, ask_pass)
153152
end
154153
end)
155154
end,
156-
on_exit = function(_, _, data)
155+
on_exit = function(jid, _, data)
156+
if jid ~= sshfs_job_id then
157+
return
158+
end
157159
handler.on_exit_handler(data, mount_dir, skip_clean, function()
158160
sshfs_job_id = nil
159161
mount_point = nil
160162
current_host = nil
161163
end)
162164
end,
163165
})
164-
-- If using password, send it on stdin
166+
if id <= 0 then
167+
vim.notify("[remote-sshfs] failed to start sshfs (code " .. tostring(id) .. ")", vim.log.levels.ERROR)
168+
return
169+
end
170+
sshfs_job_id = id
171+
mount_point = spec_mount_point
172+
current_host = spec_host
165173
if ask_pass then
166-
local password = vim.fn.inputsecret "Enter password for host: "
167-
vim.fn.chansend(sshfs_job_id, password .. "\n")
174+
local password = vim.fn.inputsecret("Enter password for host: ")
175+
vim.fn.chansend(id, password .. "\n")
168176
end
169177
end
170178
start_job()

lua/remote-sshfs/utils.lua

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ local M = {}
55
M.setup_sshfs = function(config)
66
local sshfs_folder = config.mounts.base_dir
77
if not vim.loop.fs_stat(sshfs_folder) then
8-
vim.loop.fs_mkdir(sshfs_folder, tonumber("700", 8), function(err)
9-
if err then
10-
vim.notify("Error creating mount base dir (" .. sshfs_folder .. "):", err)
11-
return
12-
end
13-
end)
8+
local ok, err = vim.loop.fs_mkdir(sshfs_folder, tonumber("700", 8))
9+
if not ok then
10+
vim.notify("Error creating mount base dir (" .. sshfs_folder .. "): " .. tostring(err), vim.log.levels.ERROR)
11+
end
1412
end
1513
end
1614

@@ -23,15 +21,13 @@ M.setup_mount_dir = function(mount_dir, callback)
2321
log.line("util", "Setting up mount directory " .. mount_dir)
2422
if not M.file_exists(mount_dir) then
2523
log.line("util", "Creating mount directory " .. mount_dir)
26-
local success = vim.loop.fs_mkdir(mount_dir, tonumber("700", 8))
27-
if not success then
28-
vim.notify("Error creating mount directory (" .. mount_dir .. ").")
29-
else
30-
callback()
24+
local ok, err = vim.loop.fs_mkdir(mount_dir, tonumber("700", 8))
25+
if not ok then
26+
vim.notify("Error creating mount directory (" .. mount_dir .. "): " .. tostring(err), vim.log.levels.ERROR)
27+
return
3128
end
32-
else
33-
callback()
3429
end
30+
callback()
3531
end
3632

3733
M.cleanup_mount_dir = function(mount_dir, callback)

0 commit comments

Comments
 (0)