fix(ssh): garbled output when directory has broken symlinks

The stderr was interleaving with the stdout when performing one of the
ls operations. This was causing the parsing to sometimes fail and crash.
This commit is contained in:
Steven Arcangeli 2024-05-01 16:10:10 -07:00
parent f3a31eba24
commit bcfc0a2e01

View file

@ -175,28 +175,31 @@ function SSHFS:list_dir(url, path, callback)
if any_links then if any_links then
-- If there were any soft links, then we need to run another ls command with -L so that we can -- 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 -- resolve the type of the link target
self.conn:run("ls -aLl --color=never" .. path_postfix, function(link_err, link_lines) self.conn:run(
-- Ignore exit code 1. That just means one of the links could not be resolved. "ls -aLl --color=never" .. path_postfix .. " 2> /dev/null",
if link_err and not link_err:match("^1:") then function(link_err, link_lines)
return callback(link_err) -- Ignore exit code 1. That just means one of the links could not be resolved.
end if link_err and not link_err:match("^1:") then
assert(link_lines) return callback(link_err)
for _, line in ipairs(link_lines) do end
if line ~= "" and not line:match("^total") then assert(link_lines)
local ok, name, type, meta = pcall(parse_ls_line, line) for _, line in ipairs(link_lines) do
if ok and name ~= "." and name ~= ".." then if line ~= "" and not line:match("^total") then
local cache_entry = entries[name] local ok, name, type, meta = pcall(parse_ls_line, line)
if cache_entry[FIELD_TYPE] == "link" then if ok and name ~= "." and name ~= ".." then
cache_entry[FIELD_META].link_stat = { local cache_entry = entries[name]
type = type, if cache_entry[FIELD_TYPE] == "link" then
size = meta.size, cache_entry[FIELD_META].link_stat = {
} type = type,
size = meta.size,
}
end
end end
end end
end end
callback(nil, cache_entries)
end end
callback(nil, cache_entries) )
end)
else else
callback(nil, cache_entries) callback(nil, cache_entries)
end end