@@ -188,27 +188,49 @@ local function process_node(context, path)
188188 on_directory_loaded (context , path )
189189end
190190
191+ --- @param err string libuv error
192+ --- @return boolean is_permission_error
193+ local function is_permission_error (err )
194+ -- Permission errors may be common when scanning over lots of folders;
195+ -- this is used to check for them and log to `debug` instead of `error`.
196+ return vim .startswith (err , " EPERM" ) or vim .startswith (err , " EACCES" )
197+ end
198+
191199local function get_children_sync (path )
192200 local children = {}
193- local success , dir = pcall (vim .loop .fs_opendir , path , nil , 1000 )
194- if not success then
195- log .error (" Error opening dir:" , dir )
201+ local dir , err = uv .fs_opendir (path , nil , 1000 )
202+ if err then
203+ if is_permission_error (err ) then
204+ log .debug (err )
205+ else
206+ log .error (err )
207+ end
208+ return children
196209 end
197- local success2 , stats = pcall ( vim . loop . fs_readdir , dir )
198- if success2 and stats then
210+ local stats = uv . fs_readdir ( dir )
211+ if stats then
199212 for _ , stat in ipairs (stats ) do
200213 local child_path = utils .path_join (path , stat .name )
201214 table.insert (children , { path = child_path , type = stat .type })
202215 end
203216 end
204- pcall ( vim . loop . fs_closedir , dir )
217+ uv . fs_closedir ( dir )
205218 return children
206219end
207220
208221local function get_children_async (path , callback )
209- uv .fs_opendir (path , function (_ , dir )
222+ local children = {}
223+ uv .fs_opendir (path , function (err , dir )
224+ if err then
225+ if is_permission_error (err ) then
226+ log .debug (err )
227+ else
228+ log .error (err )
229+ end
230+ callback (children )
231+ return
232+ end
210233 uv .fs_readdir (dir , function (_ , stats )
211- local children = {}
212234 if stats then
213235 for _ , stat in ipairs (stats ) do
214236 local child_path = utils .path_join (path , stat .name )
0 commit comments