Skip to content

Commit e2b3156

Browse files
committed
fs: improve ExistsSync performance
1 parent d335487 commit e2b3156

File tree

1 file changed

+1
-18
lines changed

1 file changed

+1
-18
lines changed

src/node_file.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,24 +1003,7 @@ static void ExistsSync(const FunctionCallbackInfo<Value>& args) {
10031003
THROW_IF_INSUFFICIENT_PERMISSIONS(
10041004
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
10051005

1006-
uv_fs_t req;
1007-
auto make = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
1008-
FS_SYNC_TRACE_BEGIN(access);
1009-
int err = uv_fs_access(nullptr, &req, path.out(), 0, nullptr);
1010-
FS_SYNC_TRACE_END(access);
1011-
1012-
#ifdef _WIN32
1013-
// In case of an invalid symlink, `uv_fs_access` on win32
1014-
// will **not** return an error and is therefore not enough.
1015-
// Double check with `uv_fs_stat()`.
1016-
if (err == 0) {
1017-
FS_SYNC_TRACE_BEGIN(stat);
1018-
err = uv_fs_stat(nullptr, &req, path.out(), nullptr);
1019-
FS_SYNC_TRACE_END(stat);
1020-
}
1021-
#endif // _WIN32
1022-
1023-
args.GetReturnValue().Set(err == 0);
1006+
args.GetReturnValue().Set(std::filesystem::exists(path.ToStringView()));
10241007
}
10251008

10261009
// Used to speed up module loading. Returns 0 if the path refers to

0 commit comments

Comments
 (0)