fs: fix misplaced errors in fs.symlinkSync
The ctx.error is supposed to be handled in fs.readlinkSync, but was handled in fs.symlinkSync by mistake. Also fix the error number check in readlink to be consistent with SYNC_CALL. PR-URL: https://github.com/nodejs/node/pull/18548 Refs: https://github.com/nodejs/node/pull/18348 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
e9b5b4fae3
commit
b1c6ecb2c6
10
lib/fs.js
10
lib/fs.js
@ -1161,6 +1161,11 @@ fs.readlinkSync = function(path, options) {
|
||||
options.encoding, undefined, ctx);
|
||||
if (ctx.errno !== undefined) {
|
||||
throw errors.uvException(ctx);
|
||||
} else if (ctx.error) {
|
||||
// TODO(joyeecheung): this is an encoding error usually caused by memory
|
||||
// problems. We need to figure out proper error code(s) for this.
|
||||
Error.captureStackTrace(ctx.error);
|
||||
throw ctx.error;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@ -1232,11 +1237,6 @@ fs.symlinkSync = function(target, path, type) {
|
||||
|
||||
if (ctx.errno !== undefined) {
|
||||
throw errors.uvException(ctx);
|
||||
} else if (ctx.error) {
|
||||
// TODO(joyeecheung): this is an encoding error usually caused by memory
|
||||
// problems. We need to figure out proper error code(s) for this.
|
||||
Error.captureStackTrace(ctx.error);
|
||||
throw ctx.error;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -886,7 +886,7 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
|
||||
fs_req_wrap req;
|
||||
int err = SyncCall(env, args[3], &req, "readlink",
|
||||
uv_fs_readlink, *path);
|
||||
if (err) {
|
||||
if (err < 0) {
|
||||
return; // syscall failed, no need to continue, error info is in ctx
|
||||
}
|
||||
const char* link_path = static_cast<const char*>(req.req.ptr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user