Skip to content

Commit

Permalink
fs: throw errors from fs.unlinkSync in JS
Browse files Browse the repository at this point in the history
PR-URL: #18348
Refs: #18106
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
joyeecheung committed Feb 1, 2018
1 parent eca93e6 commit 776f6cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,11 @@ fs.unlinkSync = function(path) {
handleError((path = getPathFromURL(path)));
nullCheck(path);
validatePath(path);
return binding.unlink(pathModule.toNamespacedPath(path));
const ctx = { path };
binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx);
if (ctx.errno !== undefined) {
throw new errors.uvException(ctx);
}
};

fs.fchmod = function(fd, mode, callback) {
Expand Down
14 changes: 9 additions & 5 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -777,17 +777,21 @@ static void Fsync(const FunctionCallbackInfo<Value>& args) {
static void Unlink(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK_GE(args.Length(), 1);
const int argc = args.Length();
CHECK_GE(argc, 2);

BufferValue path(env->isolate(), args[0]);
CHECK_NE(*path, nullptr);

if (args[1]->IsObject()) {
CHECK_EQ(args.Length(), 2);
if (args[1]->IsObject()) { // unlink(fd, req)
CHECK_EQ(argc, 2);
AsyncCall(env, args, "unlink", UTF8, AfterNoArgs,
uv_fs_unlink, *path);
} else {
SYNC_CALL(unlink, *path, *path)
} else { // unlink(fd, undefined, ctx)
CHECK_EQ(argc, 3);
fs_req_wrap req_wrap;
SyncCall(env, args[2], &req_wrap, "unlink",
uv_fs_unlink, *path);
}
}

Expand Down

0 comments on commit 776f6cd

Please sign in to comment.