Skip to content

Commit

Permalink
fix: catch undocumented edge case in scandir()
Browse files Browse the repository at this point in the history
While libuv/vim.loop docs say that `fs_scandir_next()` either returns
`nil` or `string, string` or fails, there is an edge case on networked
filesystems. In those cases, `uv__fs_scandir()` returns the type
`UV_DIRENT_UNKNOWN` and `luv.fs_scandir_next()` [converts][1] this into
returning a single string.

This means in those cases, `name` is a string and `type` is `nil`. See
[this bug report][2].

The situation can be remedied by explicitly calling `fs_stat()` on those
files. This always fetches the correct type, as far as I can see.

[1]: https://github.com/luvit/luv/blob/master/src/fs.c#L116
[2]: luvit/luv#660
  • Loading branch information
Nico Madysa committed Jul 26, 2023
1 parent 0b4950a commit 75c0598
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lua/luasnip/util/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ function Path.scandir(root)
while name do
name, type = uv.fs_scandir_next(fs)
local path = Path.join(root, name)
-- On networked filesystems, it can happen that we get
-- a name, but no type. In this case, we must query the
-- type manually via fs_stat(). See issue:
-- https://github.com/luvit/luv/issues/660
if name and not type then
local stat = uv.fs_stat(path)
type = stat and stat.type
end
if type == "file" then
table.insert(files, path)
elseif type == "directory" then
Expand Down

0 comments on commit 75c0598

Please sign in to comment.