Skip to content

Commit

Permalink
fix(find): handle directory read errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Feb 16, 2024
1 parent d1417bc commit f6048f3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lua/neotest/lib/file/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ function M.find(root, opts)
local err, dir_handle = uv.fs_opendir(root, max_entries)
assert(not err, err)
while dir_handle or #dirs_to_scan > 0 do
if not dir_handle then
while not dir_handle and #dirs_to_scan > 0 do
dir = table.remove(dirs_to_scan, 1)
logger.debug("Scanning directory:", dir)
err, dir_handle = uv.fs_opendir(root .. sep .. dir, max_entries)
assert(not err, err)
if err then
logger.error("Error opening directory:", dir, err)
end
end

local iter_dir = function()
Expand All @@ -48,9 +50,9 @@ function M.find(root, opts)
local name, path_type = entry.name, entry.type
local rel_path = name and (dir == "" and name or (dir .. sep .. name))
if
path_type == "directory"
and name:sub(1, 1) ~= "."
and (not filter_dir or filter_dir(name, rel_path, root))
path_type == "directory"
and name:sub(1, 1) ~= "."
and (not filter_dir or filter_dir(name, rel_path, root))
then
dirs_to_scan[#dirs_to_scan + 1] = rel_path
elseif path_type == "file" then
Expand Down

0 comments on commit f6048f3

Please sign in to comment.