diff --git a/lib/fs.js b/lib/fs.js index 77c6998e531e1c..4cf7d51f09573b 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -441,7 +441,11 @@ fs.existsSync = function(path) { return false; } nullCheck(path); - binding.stat(pathModule.toNamespacedPath(path)); + const ctx = { path }; + binding.stat(pathModule.toNamespacedPath(path), undefined, ctx); + if (ctx.errno !== undefined) { + return false; + } return true; } catch (e) { return false; @@ -1127,7 +1131,11 @@ fs.statSync = function(path) { handleError((path = getPathFromURL(path))); nullCheck(path); validatePath(path); - binding.stat(pathModule.toNamespacedPath(path)); + const ctx = { path }; + binding.stat(pathModule.toNamespacedPath(path), undefined, ctx); + if (ctx.errno !== undefined) { + throw new errors.uvException(ctx); + } return statsFromValues(); }; @@ -1927,7 +1935,11 @@ fs.realpathSync = function realpathSync(p, options) { } } if (linkTarget === null) { - binding.stat(baseLong); + const ctx = { path: base }; + binding.stat(baseLong, undefined, ctx); + if (ctx.errno !== undefined) { + throw new errors.uvException(ctx); + } linkTarget = binding.readlink(baseLong); } resolvedLink = pathModule.resolve(previous, linkTarget); diff --git a/src/node_file.cc b/src/node_file.cc index 4566f08c1a6454..7054338c07f82d 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -539,6 +539,7 @@ static void InternalModuleStat(const FunctionCallbackInfo& args) { static void Stat(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); + Local context = env->context(); CHECK_GE(args.Length(), 1); @@ -549,10 +550,14 @@ static void Stat(const FunctionCallbackInfo& args) { CHECK_EQ(args.Length(), 2); AsyncCall(env, args, "stat", UTF8, AfterStat, uv_fs_stat, *path); - } else { // stat(path) - SYNC_CALL(stat, *path, *path) - FillStatsArray(env->fs_stats_field_array(), - static_cast(SYNC_REQ.ptr)); + } else { // stat(path, undefined, ctx) + CHECK_EQ(args.Length(), 3); + fs_req_wrap req_wrap; + int err = SyncCall(env, args[2], &req_wrap, "stat", uv_fs_stat, *path); + if (err == 0) { + FillStatsArray(env->fs_stats_field_array(), + static_cast(req_wrap.req.ptr)); + } } }