mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 18:41:48 +00:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user