@@ -794,6 +794,22 @@ void AfterStat(uv_fs_t* req) {
794794 }
795795}
796796
797+ void AfterStatNoThrowIfNoEntry (uv_fs_t * req) {
798+ FSReqBase* req_wrap = FSReqBase::from_req (req);
799+ FSReqAfterScope after (req_wrap, req);
800+
801+ FS_ASYNC_TRACE_END1 (
802+ req->fs_type , req_wrap, " result" , static_cast <int >(req->result ))
803+ if (req->result == UV_ENOENT || req->result == UV_ENOTDIR ) {
804+ req_wrap->Resolve (Undefined (req_wrap->env ()->isolate ()));
805+ return ;
806+ }
807+
808+ if (after.Proceed ()) {
809+ req_wrap->ResolveStat (&req->statbuf );
810+ }
811+ }
812+
797813void AfterStatFs (uv_fs_t * req) {
798814 FSReqBase* req_wrap = FSReqBase::from_req (req);
799815 FSReqAfterScope after (req_wrap, req);
@@ -1087,7 +1103,9 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
10871103 ToNamespacedPath (env, &path);
10881104
10891105 bool use_bigint = args[1 ]->IsTrue ();
1090- if (!args[2 ]->IsUndefined ()) { // stat(path, use_bigint, req)
1106+ if (!args[2 ]->IsUndefined ()) { // stat(path, use_bigint, req,
1107+ // do_not_throw_if_no_entry)
1108+ bool do_not_throw_if_no_entry = args[3 ]->IsFalse ();
10911109 FSReqBase* req_wrap_async = GetReqWrap (args, 2 , use_bigint);
10921110 CHECK_NOT_NULL (req_wrap_async);
10931111 ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS (
@@ -1097,8 +1115,25 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
10971115 path.ToStringView ());
10981116 FS_ASYNC_TRACE_BEGIN1 (
10991117 UV_FS_STAT , req_wrap_async, " path" , TRACE_STR_COPY (*path))
1100- AsyncCall (env, req_wrap_async, args, " stat" , UTF8 , AfterStat,
1101- uv_fs_stat, *path);
1118+ if (do_not_throw_if_no_entry) {
1119+ AsyncCall (env,
1120+ req_wrap_async,
1121+ args,
1122+ " stat" ,
1123+ UTF8 ,
1124+ AfterStatNoThrowIfNoEntry,
1125+ uv_fs_stat,
1126+ *path);
1127+ } else {
1128+ AsyncCall (env,
1129+ req_wrap_async,
1130+ args,
1131+ " stat" ,
1132+ UTF8 ,
1133+ AfterStat,
1134+ uv_fs_stat,
1135+ *path);
1136+ }
11021137 } else { // stat(path, use_bigint, undefined, do_not_throw_if_no_entry)
11031138 THROW_IF_INSUFFICIENT_PERMISSIONS (
11041139 env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
0 commit comments