fs: throw errors from fs.symlinkSync 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
bf6ce47259
commit
32bf0f6c5b
16
lib/fs.js
16
lib/fs.js
@ -1220,6 +1220,7 @@ fs.symlink = function(target, path, type_, callback_) {
|
|||||||
const flags = stringToSymlinkType(type);
|
const flags = stringToSymlinkType(type);
|
||||||
const req = new FSReqWrap();
|
const req = new FSReqWrap();
|
||||||
req.oncomplete = callback;
|
req.oncomplete = callback;
|
||||||
|
|
||||||
binding.symlink(preprocessSymlinkDestination(target, type, path),
|
binding.symlink(preprocessSymlinkDestination(target, type, path),
|
||||||
pathModule.toNamespacedPath(path), flags, req);
|
pathModule.toNamespacedPath(path), flags, req);
|
||||||
};
|
};
|
||||||
@ -1234,8 +1235,19 @@ fs.symlinkSync = function(target, path, type) {
|
|||||||
validatePath(target, 'target');
|
validatePath(target, 'target');
|
||||||
validatePath(path);
|
validatePath(path);
|
||||||
const flags = stringToSymlinkType(type);
|
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) {
|
fs.link = function(existingPath, newPath, callback) {
|
||||||
|
@ -598,22 +598,26 @@ static void FStat(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void Symlink(const FunctionCallbackInfo<Value>& args) {
|
static void Symlink(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(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]);
|
BufferValue target(env->isolate(), args[0]);
|
||||||
CHECK_NE(*target, nullptr);
|
CHECK_NE(*target, nullptr);
|
||||||
BufferValue path(env->isolate(), args[1]);
|
BufferValue path(env->isolate(), args[1]);
|
||||||
CHECK_NE(*path, nullptr);
|
CHECK_NE(*path, nullptr);
|
||||||
|
|
||||||
CHECK(args[2]->IsUint32());
|
CHECK(args[2]->IsInt32());
|
||||||
int flags = args[2]->Uint32Value(env->context()).ToChecked();
|
int flags = args[2].As<Int32>()->Value();
|
||||||
|
|
||||||
if (args[3]->IsObject()) { // symlink(target, path, flags, req)
|
if (args[3]->IsObject()) { // symlink(target, path, flags, req)
|
||||||
CHECK_EQ(args.Length(), 4);
|
CHECK_EQ(args.Length(), 4);
|
||||||
AsyncDestCall(env, args, "symlink", *path, path.length(), UTF8,
|
AsyncDestCall(env, args, "symlink", *path, path.length(), UTF8,
|
||||||
AfterNoArgs, uv_fs_symlink, *target, *path, flags);
|
AfterNoArgs, uv_fs_symlink, *target, *path, flags);
|
||||||
} else { // symlink(target, path, flags)
|
} else { // symlink(target, path, flags, undefinec, ctx)
|
||||||
SYNC_DEST_CALL(symlink, *target, *path, *target, *path, flags)
|
CHECK_EQ(argc, 5);
|
||||||
|
fs_req_wrap req_wrap;
|
||||||
|
SyncCall(env, args[4], &req_wrap, "symlink",
|
||||||
|
uv_fs_symlink, *target, *path, flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user