Skip to content

Commit

Permalink
fix: Handle users and groups with spaces over SSH (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
annagrram authored Jul 21, 2024
1 parent 9e5eb2f commit a6cea1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lua/oil/adapters/ssh/connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ function SSHConnection.new(url)
else
self.jid = jid
end
self:run("whoami", function(err, lines)
self:run("id -u", function(err, lines)
if err then
vim.notify(string.format("Error fetching ssh connection user: %s", err), vim.log.levels.WARN)
else
assert(lines)
self.meta.user = vim.trim(table.concat(lines, ""))
end
end)
self:run("groups", function(err, lines)
self:run("id -G", function(err, lines)
if err then
vim.notify(
string.format("Error fetching ssh connection user groups: %s", err),
Expand Down
8 changes: 4 additions & 4 deletions lua/oil/adapters/ssh/sshfs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local typechar_map = {
---@return table Metadata for entry
local function parse_ls_line(line)
local typechar, perms, refcount, user, group, rem =
line:match("^(.)(%S+)%s+(%d+)%s+(%S+)%s+(%S+)%s+(.*)$")
line:match("^(.)(%S+)%s+(%d+)%s+(%d+)%s+(%d+)%s+(.*)$")
if not typechar then
error(string.format("Could not parse '%s'", line))
end
Expand Down Expand Up @@ -112,7 +112,7 @@ function SSHFS:realpath(path, callback)
abspath = abspath:sub(1, #abspath - 1)
end
self.conn:run(
string.format("ls -ald --color=never %s", shellescape(abspath)),
string.format("ls -land --color=never %s", shellescape(abspath)),
function(ls_err, ls_lines)
local type
if ls_err then
Expand Down Expand Up @@ -142,7 +142,7 @@ function SSHFS:list_dir(url, path, callback)
if path ~= "" then
path_postfix = string.format(" %s", shellescape(path))
end
self.conn:run("LANG=C ls -al --color=never" .. path_postfix, function(err, lines)
self.conn:run("LANG=C ls -lan --color=never" .. path_postfix, function(err, lines)
if err then
if err:match("No such file or directory%s*$") then
-- If the directory doesn't exist, treat the list as a success. We will be able to traverse
Expand Down Expand Up @@ -176,7 +176,7 @@ function SSHFS:list_dir(url, path, callback)
-- If there were any soft links, then we need to run another ls command with -L so that we can
-- resolve the type of the link target
self.conn:run(
"ls -aLl --color=never" .. path_postfix .. " 2> /dev/null",
"ls -naLl --color=never" .. path_postfix .. " 2> /dev/null",
function(link_err, link_lines)
-- Ignore exit code 1. That just means one of the links could not be resolved.
if link_err and not link_err:match("^1:") then
Expand Down

0 comments on commit a6cea1a

Please sign in to comment.