@@ -801,6 +801,22 @@ void AfterStat(uv_fs_t* req) {
801801 }
802802}
803803
804+ void AfterStatNoThrowIfNoEntry (uv_fs_t * req) {
805+ FSReqBase* req_wrap = FSReqBase::from_req (req);
806+ FSReqAfterScope after (req_wrap, req);
807+
808+ FS_ASYNC_TRACE_END1 (
809+ req->fs_type , req_wrap, " result" , static_cast <int >(req->result ))
810+ if (req->result == UV_ENOENT || req->result == UV_ENOTDIR) {
811+ req_wrap->Resolve (Undefined (req_wrap->env ()->isolate ()));
812+ return ;
813+ }
814+
815+ if (after.Proceed ()) {
816+ req_wrap->ResolveStat (&req->statbuf );
817+ }
818+ }
819+
804820void AfterStatFs (uv_fs_t * req) {
805821 FSReqBase* req_wrap = FSReqBase::from_req (req);
806822 FSReqAfterScope after (req_wrap, req);
@@ -1096,7 +1112,9 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
10961112 ToNamespacedPath (env, &path);
10971113
10981114 bool use_bigint = args[1 ]->IsTrue ();
1099- if (!args[2 ]->IsUndefined ()) { // stat(path, use_bigint, req)
1115+ if (!args[2 ]->IsUndefined ()) { // stat(path, use_bigint, req,
1116+ // do_not_throw_if_no_entry)
1117+ bool do_not_throw_if_no_entry = args[3 ]->IsFalse ();
11001118 FSReqBase* req_wrap_async = GetReqWrap (args, 2 , use_bigint);
11011119 CHECK_NOT_NULL (req_wrap_async);
11021120 ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS (
@@ -1106,8 +1124,25 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
11061124 path.ToStringView ());
11071125 FS_ASYNC_TRACE_BEGIN1 (
11081126 UV_FS_STAT, req_wrap_async, " path" , TRACE_STR_COPY (*path))
1109- AsyncCall (env, req_wrap_async, args, " stat" , UTF8, AfterStat,
1110- uv_fs_stat, *path);
1127+ if (do_not_throw_if_no_entry) {
1128+ AsyncCall (env,
1129+ req_wrap_async,
1130+ args,
1131+ " stat" ,
1132+ UTF8,
1133+ AfterStatNoThrowIfNoEntry,
1134+ uv_fs_stat,
1135+ *path);
1136+ } else {
1137+ AsyncCall (env,
1138+ req_wrap_async,
1139+ args,
1140+ " stat" ,
1141+ UTF8,
1142+ AfterStat,
1143+ uv_fs_stat,
1144+ *path);
1145+ }
11111146 } else { // stat(path, use_bigint, undefined, do_not_throw_if_no_entry)
11121147 THROW_IF_INSUFFICIENT_PERMISSIONS (
11131148 env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
0 commit comments