fs: throw fchownSync errors in JS
PR-URL: https://github.com/nodejs/node/pull/19041 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
79b195437c
commit
1650eaeac4
@ -1110,7 +1110,9 @@ fs.fchownSync = function(fd, uid, gid) {
|
|||||||
validateUint32(uid, 'uid');
|
validateUint32(uid, 'uid');
|
||||||
validateUint32(gid, 'gid');
|
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) {
|
fs.chown = function(path, uid, gid, callback) {
|
||||||
|
@ -1552,20 +1552,27 @@ static void Chown(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void FChown(const FunctionCallbackInfo<Value>& args) {
|
static void FChown(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
|
|
||||||
CHECK(args[0]->IsInt32());
|
const int argc = args.Length();
|
||||||
CHECK(args[1]->IsUint32());
|
CHECK_GE(argc, 3);
|
||||||
CHECK(args[2]->IsUint32());
|
|
||||||
|
|
||||||
int fd = args[0]->Int32Value();
|
CHECK(args[0]->IsInt32());
|
||||||
uv_uid_t uid = static_cast<uv_uid_t>(args[1]->Uint32Value());
|
const int fd = args[0].As<Int32>()->Value();
|
||||||
uv_gid_t gid = static_cast<uv_gid_t>(args[2]->Uint32Value());
|
|
||||||
|
CHECK(args[1]->IsUint32());
|
||||||
|
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Uint32>()->Value());
|
||||||
|
|
||||||
|
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]);
|
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,
|
AsyncCall(env, req_wrap, args, "fchown", UTF8, AfterNoArgs,
|
||||||
uv_fs_fchown, fd, uid, gid);
|
uv_fs_fchown, fd, uid, gid);
|
||||||
} else {
|
} else { // fchown(fd, uid, gid, undefined, ctx)
|
||||||
SYNC_CALL(fchown, 0, fd, uid, gid);
|
CHECK_EQ(argc, 5);
|
||||||
|
fs_req_wrap req_wrap;
|
||||||
|
SyncCall(env, args[4], &req_wrap, "fchown",
|
||||||
|
uv_fs_fchown, fd, uid, gid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user