Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fs: throw fchownSync errors in JS
  • Loading branch information
joyeecheung committed Feb 27, 2018
commit fbdd350a21e5f55bd87cc33634bee95ca69eb6f2
4 changes: 3 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,9 @@ fs.fchownSync = function(fd, uid, gid) {
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');

return binding.fchown(fd, uid, gid);
const ctx = {};
binding.fchown(fd, uid, gid, undefined, ctx);
handleErrorFromBinding(ctx);
};

fs.chown = function(path, uid, gid, callback) {
Expand Down
21 changes: 14 additions & 7 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1552,20 +1552,27 @@ static void Chown(const FunctionCallbackInfo<Value>& args) {
static void FChown(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

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

CHECK(args[0]->IsInt32());
const int fd = args[0].As<Int32>()->Value();

CHECK(args[1]->IsUint32());
CHECK(args[2]->IsUint32());
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());

int fd = args[0]->Int32Value();
uv_uid_t uid = static_cast<uv_uid_t>(args[1]->Uint32Value());
uv_gid_t gid = static_cast<uv_gid_t>(args[2]->Uint32Value());
CHECK(args[2]->IsUint32());
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Uint32>()->Value());

FSReqBase* req_wrap = GetReqWrap(env, args[3]);
if (req_wrap != nullptr) {
if (req_wrap != nullptr) { // fchown(fd, uid, gid, req)
AsyncCall(env, req_wrap, args, "fchown", UTF8, AfterNoArgs,
uv_fs_fchown, fd, uid, gid);
} else {
SYNC_CALL(fchown, 0, fd, uid, gid);
} else { // fchown(fd, uid, gid, undefined, ctx)
CHECK_EQ(argc, 5);
fs_req_wrap req_wrap;
SyncCall(env, args[4], &req_wrap, "fchown",
uv_fs_fchown, fd, uid, gid);
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-fs-error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,3 +749,24 @@ if (!common.isAIX) {
);
});
}

// fchown
if (!common.isWindows) {
const validateError = (err) => {
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fchown');
assert.strictEqual(err.errno, uv.UV_EBADF);
assert.strictEqual(err.code, 'EBADF');
assert.strictEqual(err.syscall, 'fchown');
return true;
};

common.runWithInvalidFD((fd) => {
fs.fchown(fd, process.getuid(), process.getgid(),
common.mustCall(validateError));

assert.throws(
() => fs.fchownSync(fd, process.getuid(), process.getgid()),
validateError
);
});
}