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:
parent
32bf0f6c5b
commit
167e22937c
11
lib/fs.js
11
lib/fs.js
@ -1280,8 +1280,15 @@ fs.linkSync = function(existingPath, newPath) {
|
|||||||
nullCheck(newPath);
|
nullCheck(newPath);
|
||||||
validatePath(existingPath, 'existingPath');
|
validatePath(existingPath, 'existingPath');
|
||||||
validatePath(newPath, 'newPath');
|
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) {
|
fs.unlink = function(path, callback) {
|
||||||
|
@ -624,7 +624,8 @@ static void Symlink(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void Link(const FunctionCallbackInfo<Value>& args) {
|
static void Link(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(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]);
|
BufferValue src(env->isolate(), args[0]);
|
||||||
CHECK_NE(*src, nullptr);
|
CHECK_NE(*src, nullptr);
|
||||||
@ -633,11 +634,14 @@ static void Link(const FunctionCallbackInfo<Value>& args) {
|
|||||||
CHECK_NE(*dest, nullptr);
|
CHECK_NE(*dest, nullptr);
|
||||||
|
|
||||||
if (args[2]->IsObject()) { // link(src, dest, req)
|
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,
|
AsyncDestCall(env, args, "link", *dest, dest.length(), UTF8,
|
||||||
AfterNoArgs, uv_fs_link, *src, *dest);
|
AfterNoArgs, uv_fs_link, *src, *dest);
|
||||||
} else { // link(src, dest)
|
} else { // link(src, dest, undefined, ctx)
|
||||||
SYNC_DEST_CALL(link, *src, *dest, *src, *dest)
|
CHECK_EQ(argc, 4);
|
||||||
|
fs_req_wrap req_wrap;
|
||||||
|
SyncCall(env, args[3], &req_wrap, "link",
|
||||||
|
uv_fs_link, *src, *dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user