Skip to content

Commit f2ef348

Browse files
committed
fs: handle UV_ENOTDIR in fs.statSync with throwIfNoEntry provided
Fixes: #56993 Signed-off-by: Juan José Arboleda <[email protected]>
1 parent 29bc969 commit f2ef348

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/node_file.cc

Lines changed: 5 additions & 1 deletion
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>();
@@ -1122,7 +1126,7 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
11221126
int result;
11231127
if (do_not_throw_if_no_entry) {
11241128
result = SyncCallAndThrowIf(
1125-
is_uv_error_except_no_entry, env, &req_wrap_sync, uv_fs_stat, *path);
1129+
is_uv_error_except_no_entry_dir, env, &req_wrap_sync, uv_fs_stat, *path);
11261130
} else {
11271131
result = SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_stat, *path);
11281132
}

test/parallel/test-fs-stat.js

Lines changed: 5 additions & 0 deletions
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)