fs: throw errors from fs.linkSync in JS

PR-URL: https://github.com/nodejs/node/pull/18348
Refs: https://github.com/nodejs/node/issues/18106
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Joyee Cheung 2018-01-24 07:03:11 +08:00
parent 32bf0f6c5b
commit 167e22937c
No known key found for this signature in database
GPG Key ID: F586868AAD831D0C
2 changed files with 17 additions and 6 deletions

View File

@ -1280,8 +1280,15 @@ fs.linkSync = function(existingPath, newPath) {
nullCheck(newPath);
validatePath(existingPath, 'existingPath');
validatePath(newPath, 'newPath');
return binding.link(pathModule.toNamespacedPath(existingPath),
pathModule.toNamespacedPath(newPath));
const ctx = { path: existingPath, dest: newPath };
const result = binding.link(pathModule.toNamespacedPath(existingPath),
pathModule.toNamespacedPath(newPath),
undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
}
return result;
};
fs.unlink = function(path, callback) {

View File

@ -624,7 +624,8 @@ static void Symlink(const FunctionCallbackInfo<Value>& args) {
static void Link(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 2);
int argc = args.Length();
CHECK_GE(argc, 3);
BufferValue src(env->isolate(), args[0]);
CHECK_NE(*src, nullptr);
@ -633,11 +634,14 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
CHECK_NE(*dest, nullptr);
if (args[2]->IsObject()) { // link(src, dest, req)
CHECK_EQ(args.Length(), 3);
CHECK_EQ(argc, 3);
AsyncDestCall(env, args, "link", *dest, dest.length(), UTF8,
AfterNoArgs, uv_fs_link, *src, *dest);
} else { // link(src, dest)
SYNC_DEST_CALL(link, *src, *dest, *src, *dest)
} else { // link(src, dest, undefined, ctx)
CHECK_EQ(argc, 4);
fs_req_wrap req_wrap;
SyncCall(env, args[3], &req_wrap, "link",
uv_fs_link, *src, *dest);
}
}