@@ -810,6 +810,22 @@ void AfterStat(uv_fs_t* req) {
810810 }
811811}
812812
813+ void AfterStatNoThrowIfNoEntry (uv_fs_t * req) {
814+ FSReqBase* req_wrap = FSReqBase::from_req (req);
815+ FSReqAfterScope after (req_wrap, req);
816+
817+ FS_ASYNC_TRACE_END1 (
818+ req->fs_type , req_wrap, " result" , static_cast <int >(req->result ))
819+ if (req->result == UV_ENOENT || req->result == UV_ENOTDIR) {
820+ req_wrap->Resolve (Undefined (req_wrap->env ()->isolate ()));
821+ return ;
822+ }
823+
824+ if (after.Proceed ()) {
825+ req_wrap->ResolveStat (&req->statbuf );
826+ }
827+ }
828+
813829void AfterStatFs (uv_fs_t * req) {
814830 FSReqBase* req_wrap = FSReqBase::from_req (req);
815831 FSReqAfterScope after (req_wrap, req);
@@ -1105,7 +1121,9 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
11051121 ToNamespacedPath (env, &path);
11061122
11071123 bool use_bigint = args[1 ]->IsTrue ();
1108- if (!args[2 ]->IsUndefined ()) { // stat(path, use_bigint, req)
1124+ if (!args[2 ]->IsUndefined ()) { // stat(path, use_bigint, req,
1125+ // do_not_throw_if_no_entry)
1126+ bool do_not_throw_if_no_entry = args[3 ]->IsFalse ();
11091127 FSReqBase* req_wrap_async = GetReqWrap (args, 2 , use_bigint);
11101128 CHECK_NOT_NULL (req_wrap_async);
11111129 ASYNC_THROW_IF_INSUFFICIENT_PERMISSIONS (
@@ -1115,8 +1133,25 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
11151133 path.ToStringView ());
11161134 FS_ASYNC_TRACE_BEGIN1 (
11171135 UV_FS_STAT, req_wrap_async, " path" , TRACE_STR_COPY (*path))
1118- AsyncCall (env, req_wrap_async, args, " stat" , UTF8, AfterStat,
1119- uv_fs_stat, *path);
1136+ if (do_not_throw_if_no_entry) {
1137+ AsyncCall (env,
1138+ req_wrap_async,
1139+ args,
1140+ " stat" ,
1141+ UTF8,
1142+ AfterStatNoThrowIfNoEntry,
1143+ uv_fs_stat,
1144+ *path);
1145+ } else {
1146+ AsyncCall (env,
1147+ req_wrap_async,
1148+ args,
1149+ " stat" ,
1150+ UTF8,
1151+ AfterStat,
1152+ uv_fs_stat,
1153+ *path);
1154+ }
11201155 } else { // stat(path, use_bigint, undefined, do_not_throw_if_no_entry)
11211156 THROW_IF_INSUFFICIENT_PERMISSIONS (
11221157 env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
0 commit comments