Skip to content

Commit 40f3a51

Browse files
juanarboltargos
authored andcommitted
fs: handle UV_ENOTDIR in fs.statSync with throwIfNoEntry provided
Fixes: #56993 Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com> PR-URL: #56996 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a588066 commit 40f3a51

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/node_file.cc

+9-2
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,10 @@ constexpr bool is_uv_error_except_no_entry(int result) {
10881088
return result < 0 && result != UV_ENOENT;
10891089
}
10901090

1091+
constexpr bool is_uv_error_except_no_entry_dir(int result) {
1092+
return result < 0 && !(result == UV_ENOENT || result == UV_ENOTDIR);
1093+
}
1094+
10911095
static void Stat(const FunctionCallbackInfo<Value>& args) {
10921096
Realm* realm = Realm::GetCurrent(args);
10931097
BindingData* binding_data = realm->GetBindingData<BindingData>();
@@ -1121,8 +1125,11 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
11211125
FS_SYNC_TRACE_BEGIN(stat);
11221126
int result;
11231127
if (do_not_throw_if_no_entry) {
1124-
result = SyncCallAndThrowIf(
1125-
is_uv_error_except_no_entry, env, &req_wrap_sync, uv_fs_stat, *path);
1128+
result = SyncCallAndThrowIf(is_uv_error_except_no_entry_dir,
1129+
env,
1130+
&req_wrap_sync,
1131+
uv_fs_stat,
1132+
*path);
11261133
} else {
11271134
result = SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_stat, *path);
11281135
}

test/parallel/test-fs-stat.js

+5
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,8 @@ fs.lstat(__filename, undefined, common.mustCall());
221221
},
222222
);
223223
}
224+
225+
{
226+
// Test that the throwIfNoEntry option works and returns undefined
227+
assert.ok(!(fs.statSync('./wont_exists', { throwIfNoEntry: false })));
228+
}

0 commit comments

Comments
 (0)