@@ -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 ()
0 commit comments