fix(vim.fs): fs.dir() may return nil "type" on some filesystems #39749

Problem:
Currently, only some filesystems (Btrfs, ext2, ext3, ext4) have full
support of accessing the `dirent` entry-type. On other filesystems,
`uv.fs_scandir_next` may return `nil` for an existing but unsupported
entry-type.

This means consumers (such as `fs.dir()`), cannot know if `nil` means
"non-existent" or "unsupported".

Solution:
Fall back to `uv.fs_lstat` when `etype` is `nil`; return "unknown" if it
fails.
This commit is contained in:
abdulahmoda
2026-05-29 14:24:22 -04:00
committed by GitHub
parent ac352a6df6
commit 4b5f026ac9
2 changed files with 60 additions and 2 deletions

View File

@@ -252,6 +252,41 @@ describe('vim.fs', function()
end)
)
end)
describe('fs_scandir_next fallback', function()
before_each(function()
mkdir('testdir')
t.write_file('testdir/test.txt', 'test file')
end)
after_each(function()
rmdir('testdir')
end)
it('falls back to fs_lstat when fs_scandir_next returns nil type', function()
local result = n.exec_lua([[
local orig = vim.uv.fs_scandir_next
vim.uv.fs_scandir_next = function(fs)
local name = orig(fs)
if name then
return name, nil
end
return name
end
local out = {}
for name, etype in vim.fs.dir('testdir') do
out[name] = etype
end
vim.uv.fs_scandir_next = orig
return out
]])
eq('file', result['test.txt'])
end)
end)
end)
describe('find()', function()