@@ -188,27 +188,49 @@ local function process_node(context, path)
188
188
on_directory_loaded (context , path )
189
189
end
190
190
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
+
191
199
local function get_children_sync (path )
192
200
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
196
209
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
199
212
for _ , stat in ipairs (stats ) do
200
213
local child_path = utils .path_join (path , stat .name )
201
214
table.insert (children , { path = child_path , type = stat .type })
202
215
end
203
216
end
204
- pcall ( vim . loop . fs_closedir , dir )
217
+ uv . fs_closedir ( dir )
205
218
return children
206
219
end
207
220
208
221
local 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
210
233
uv .fs_readdir (dir , function (_ , stats )
211
- local children = {}
212
234
if stats then
213
235
for _ , stat in ipairs (stats ) do
214
236
local child_path = utils .path_join (path , stat .name )
0 commit comments