Skip to content

Commit

Permalink
fs: handle UV_ENOTDIR in fs.statSync with throwIfNoEntry provided
Browse files Browse the repository at this point in the history
Fixes: #56993
Signed-off-by: Juan José Arboleda <[email protected]>
  • Loading branch information
juanarbol committed Feb 12, 2025
1 parent 29bc969 commit 985b3a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,10 @@ constexpr bool is_uv_error_except_no_entry(int result) {
return result < 0 && result != UV_ENOENT;
}

constexpr bool is_uv_error_except_no_entry_dir(int result) {
return result < 0 && !(result == UV_ENOENT || result == UV_ENOTDIR);
}

static void Stat(const FunctionCallbackInfo<Value>& args) {
Realm* realm = Realm::GetCurrent(args);
BindingData* binding_data = realm->GetBindingData<BindingData>();
Expand Down Expand Up @@ -1122,7 +1126,8 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
int result;
if (do_not_throw_if_no_entry) {
result = SyncCallAndThrowIf(
is_uv_error_except_no_entry, env, &req_wrap_sync, uv_fs_stat, *path);
is_uv_error_except_no_entry_dir,
env, &req_wrap_sync, uv_fs_stat, *path);
} else {
result = SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_stat, *path);
}
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-fs-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,8 @@ fs.lstat(__filename, undefined, common.mustCall());
},
);
}

{
// Test that the throwIfNoEntry option works and returns undefined
assert.ok(!(fs.statSync('./wont_exists', { throwIfNoEntry: false })));
}

0 comments on commit 985b3a3

Please sign in to comment.