diff --git a/lib/fs.js b/lib/fs.js index 0103500f0b5..c75a8501b67 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1220,6 +1220,7 @@ fs.symlink = function(target, path, type_, callback_) { const flags = stringToSymlinkType(type); const req = new FSReqWrap(); req.oncomplete = callback; + binding.symlink(preprocessSymlinkDestination(target, type, path), pathModule.toNamespacedPath(path), flags, req); }; @@ -1234,8 +1235,19 @@ fs.symlinkSync = function(target, path, type) { validatePath(target, 'target'); validatePath(path); const flags = stringToSymlinkType(type); - return binding.symlink(preprocessSymlinkDestination(target, type, path), - pathModule.toNamespacedPath(path), flags); + + const ctx = { path: target, dest: path }; + binding.symlink(preprocessSymlinkDestination(target, type, path), + pathModule.toNamespacedPath(path), flags, undefined, ctx); + + if (ctx.errno !== undefined) { + throw new 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; + } }; fs.link = function(existingPath, newPath, callback) { diff --git a/src/node_file.cc b/src/node_file.cc index 8cbfa1b1793..d67d45d4a82 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -598,22 +598,26 @@ static void FStat(const FunctionCallbackInfo& args) { static void Symlink(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - CHECK_GE(args.Length(), 3); + int argc = args.Length(); + CHECK_GE(argc, 4); BufferValue target(env->isolate(), args[0]); CHECK_NE(*target, nullptr); BufferValue path(env->isolate(), args[1]); CHECK_NE(*path, nullptr); - CHECK(args[2]->IsUint32()); - int flags = args[2]->Uint32Value(env->context()).ToChecked(); + CHECK(args[2]->IsInt32()); + int flags = args[2].As()->Value(); if (args[3]->IsObject()) { // symlink(target, path, flags, req) CHECK_EQ(args.Length(), 4); AsyncDestCall(env, args, "symlink", *path, path.length(), UTF8, AfterNoArgs, uv_fs_symlink, *target, *path, flags); - } else { // symlink(target, path, flags) - SYNC_DEST_CALL(symlink, *target, *path, *target, *path, flags) + } else { // symlink(target, path, flags, undefinec, ctx) + CHECK_EQ(argc, 5); + fs_req_wrap req_wrap; + SyncCall(env, args[4], &req_wrap, "symlink", + uv_fs_symlink, *target, *path, flags); } }