Skip to content

Commit

Permalink
fix(ssh): bad argument when editing files over ssh (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed May 13, 2024
1 parent 010b44a commit aa0c00c
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lua/oil/adapters/ssh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ local FIELD_META = constants.FIELD_META
---@field port nil|integer
---@field path string

---@param args string[]
local function scp(args, ...)
local cmd = vim.list_extend({ "scp", "-C" }, config.extra_scp_args)
vim.list_extend(cmd, args)
shell.run(cmd, ...)
end

---@param oil_url string
---@return oil.sshUrl
M.parse_url = function(oil_url)
Expand Down Expand Up @@ -303,14 +310,7 @@ M.perform_action = function(action, cb)
local src_conn = get_connection(action.src_url)
local dest_conn = get_connection(action.dest_url)
if src_conn ~= dest_conn then
shell.run({
"scp",
unpack(config.extra_scp_args),
"-C",
"-r",
url_to_scp(src_res),
url_to_scp(dest_res),
}, function(err)
scp({ "-r", url_to_scp(src_res), url_to_scp(dest_res) }, function(err)
if err then
return cb(err)
end
Expand All @@ -329,14 +329,7 @@ M.perform_action = function(action, cb)
local src_res = M.parse_url(action.src_url)
local dest_res = M.parse_url(action.dest_url)
if not url_hosts_equal(src_res, dest_res) then
shell.run({
"scp",
unpack(config.extra_scp_args),
"-C",
"-r",
url_to_scp(src_res),
url_to_scp(dest_res),
}, cb)
scp({ "-r", url_to_scp(src_res), url_to_scp(dest_res) }, cb)
else
local src_conn = get_connection(action.src_url)
src_conn:cp(src_res.path, dest_res.path, cb)
Expand All @@ -355,7 +348,7 @@ M.perform_action = function(action, cb)
src_arg = fs.posix_to_os_path(path)
dest_arg = url_to_scp(M.parse_url(action.dest_url))
end
shell.run({ "scp", unpack(config.extra_scp_args), "-C", "-r", src_arg, dest_arg }, cb)
scp({ "-r", src_arg, dest_arg }, cb)
end
else
cb(string.format("Bad action type: %s", action.type))
Expand All @@ -379,7 +372,7 @@ M.read_file = function(bufnr)
end
local tmp_bufnr = vim.fn.bufadd(tmpfile)

shell.run({ "scp", unpack(config.extra_scp_args), "-C", scp_url, tmpfile }, function(err)
scp({ scp_url, tmpfile }, function(err)
loading.set_loading(bufnr, false)
vim.bo[bufnr].modifiable = true
vim.cmd.doautocmd({ args = { "BufReadPre", bufname }, mods = { silent = true } })
Expand Down Expand Up @@ -419,7 +412,7 @@ M.write_file = function(bufnr)
vim.cmd.write({ args = { tmpfile }, bang = true, mods = { silent = true, noautocmd = true } })
local tmp_bufnr = vim.fn.bufadd(tmpfile)

shell.run({ "scp", unpack(config.extra_scp_args), "-C", tmpfile, scp_url }, function(err)
scp({ tmpfile, scp_url }, function(err)
vim.bo[bufnr].modifiable = true
if err then
vim.notify(string.format("Error writing file: %s", err), vim.log.levels.ERROR)
Expand Down

0 comments on commit aa0c00c

Please # to comment.