@@ -367,19 +367,24 @@ static void OpenDir(const FunctionCallbackInfo<Value>& args) {
367367
368368 BufferValue path (isolate, args[0 ]);
369369 CHECK_NOT_NULL (*path);
370- THROW_IF_INSUFFICIENT_PERMISSIONS (
371- env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
372370
373371 const enum encoding encoding = ParseEncoding (isolate, args[1 ], UTF8);
374372
375373 FSReqBase* req_wrap_async = GetReqWrap (args, 2 );
376374 if (req_wrap_async != nullptr ) { // openDir(path, encoding, req)
375+ ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS (
376+ env,
377+ req_wrap_async,
378+ permission::PermissionScope::kFileSystemRead ,
379+ path.ToStringView ());
377380 FS_DIR_ASYNC_TRACE_BEGIN1 (
378381 UV_FS_OPENDIR, req_wrap_async, " path" , TRACE_STR_COPY (*path))
379382 AsyncCall (env, req_wrap_async, args, " opendir" , encoding, AfterOpenDir,
380383 uv_fs_opendir, *path);
381384 } else { // openDir(path, encoding, undefined, ctx)
382385 CHECK_EQ (argc, 4 );
386+ THROW_IF_INSUFFICIENT_PERMISSIONS (
387+ env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
383388 FSReqWrapSync req_wrap_sync;
384389 FS_DIR_SYNC_TRACE_BEGIN (opendir);
385390 int result = SyncCall (env, args[3 ], &req_wrap_sync, " opendir" ,
0 commit comments