diff --git a/lib/fs.js b/lib/fs.js index c75a8501b67428..4a69ef9bc46c33 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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) { diff --git a/src/node_file.cc b/src/node_file.cc index d67d45d4a8274d..0129d2d3f99ba1 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -624,7 +624,8 @@ static void Symlink(const FunctionCallbackInfo& args) { static void Link(const FunctionCallbackInfo& 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& 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); } }