fs: throw fs.stat{Sync} errors in JS
PR-URL: https://github.com/nodejs/node/pull/17914 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
791975d189
commit
57d7638af3
18
lib/fs.js
18
lib/fs.js
@ -441,7 +441,11 @@ fs.existsSync = function(path) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nullCheck(path);
|
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;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
@ -1127,7 +1131,11 @@ fs.statSync = function(path) {
|
|||||||
handleError((path = getPathFromURL(path)));
|
handleError((path = getPathFromURL(path)));
|
||||||
nullCheck(path);
|
nullCheck(path);
|
||||||
validatePath(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();
|
return statsFromValues();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1927,7 +1935,11 @@ fs.realpathSync = function realpathSync(p, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (linkTarget === null) {
|
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);
|
linkTarget = binding.readlink(baseLong);
|
||||||
}
|
}
|
||||||
resolvedLink = pathModule.resolve(previous, linkTarget);
|
resolvedLink = pathModule.resolve(previous, linkTarget);
|
||||||
|
@ -539,6 +539,7 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
static void Stat(const FunctionCallbackInfo<Value>& args) {
|
static void Stat(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
|
Local<Context> context = env->context();
|
||||||
|
|
||||||
CHECK_GE(args.Length(), 1);
|
CHECK_GE(args.Length(), 1);
|
||||||
|
|
||||||
@ -549,10 +550,14 @@ static void Stat(const FunctionCallbackInfo<Value>& args) {
|
|||||||
CHECK_EQ(args.Length(), 2);
|
CHECK_EQ(args.Length(), 2);
|
||||||
AsyncCall(env, args, "stat", UTF8, AfterStat,
|
AsyncCall(env, args, "stat", UTF8, AfterStat,
|
||||||
uv_fs_stat, *path);
|
uv_fs_stat, *path);
|
||||||
} else { // stat(path)
|
} else { // stat(path, undefined, ctx)
|
||||||
SYNC_CALL(stat, *path, *path)
|
CHECK_EQ(args.Length(), 3);
|
||||||
FillStatsArray(env->fs_stats_field_array(),
|
fs_req_wrap req_wrap;
|
||||||
static_cast<const uv_stat_t*>(SYNC_REQ.ptr));
|
int err = SyncCall(env, args[2], &req_wrap, "stat", uv_fs_stat, *path);
|
||||||
|
if (err == 0) {
|
||||||
|
FillStatsArray(env->fs_stats_field_array(),
|
||||||
|
static_cast<const uv_stat_t*>(req_wrap.req.ptr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user