@@ -1003,24 +1003,23 @@ static void ExistsSync(const FunctionCallbackInfo<Value>& args) {
1003
1003
THROW_IF_INSUFFICIENT_PERMISSIONS (
1004
1004
env, permission::PermissionScope::kFileSystemRead , path.ToStringView ());
1005
1005
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 );
1006
+ std::error_code error{};
1007
+ auto file_path = std::filesystem::path (path.ToStringView ());
1008
+ bool exists = false ;
1011
1009
1012
1010
#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);
1011
+ FS_SYNC_TRACE_BEGIN (stat);
1012
+ auto status = std::filesystem::status (file_path, error);
1013
+ FS_SYNC_TRACE_END (stat);
1014
+ if (!error) {
1015
+ exists = status.type () != std::filesystem::file_type::not_found;
1020
1016
}
1021
- #endif // _WIN32
1022
-
1023
- args.GetReturnValue ().Set (err == 0 );
1017
+ #else
1018
+ FS_SYNC_TRACE_BEGIN (access );
1019
+ exists = std::filesystem::exists (file_path, error);
1020
+ FS_SYNC_TRACE_END (access );
1021
+ #endif
1022
+ args.GetReturnValue ().Set (exists);
1024
1023
}
1025
1024
1026
1025
// Used to speed up module loading. Returns 0 if the path refers to
0 commit comments