fs: throw fchmodSync 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
c6acfdb3ac
commit
79b195437c
@ -1004,7 +1004,9 @@ fs.fchmodSync = function(fd, mode) {
|
|||||||
validateUint32(mode, 'mode');
|
validateUint32(mode, 'mode');
|
||||||
if (mode < 0 || mode > 0o777)
|
if (mode < 0 || mode > 0o777)
|
||||||
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'mode');
|
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'mode');
|
||||||
return binding.fchmod(fd, mode);
|
const ctx = {};
|
||||||
|
binding.fchmod(fd, mode, undefined, ctx);
|
||||||
|
handleErrorFromBinding(ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (constants.O_SYMLINK !== undefined) {
|
if (constants.O_SYMLINK !== undefined) {
|
||||||
|
@ -1493,18 +1493,24 @@ static void Chmod(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void FChmod(const FunctionCallbackInfo<Value>& args) {
|
static void FChmod(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]->IsInt32());
|
CHECK_GE(argc, 2);
|
||||||
|
|
||||||
int fd = args[0]->Int32Value();
|
CHECK(args[0]->IsInt32());
|
||||||
int mode = static_cast<int>(args[1]->Int32Value());
|
const int fd = args[0].As<Int32>()->Value();
|
||||||
|
|
||||||
|
CHECK(args[1]->IsInt32());
|
||||||
|
const int mode = args[1].As<Int32>()->Value();
|
||||||
|
|
||||||
FSReqBase* req_wrap = GetReqWrap(env, args[2]);
|
FSReqBase* req_wrap = GetReqWrap(env, args[2]);
|
||||||
if (req_wrap != nullptr) {
|
if (req_wrap != nullptr) { // fchmod(fd, mode, req)
|
||||||
AsyncCall(env, req_wrap, args, "fchmod", UTF8, AfterNoArgs,
|
AsyncCall(env, req_wrap, args, "fchmod", UTF8, AfterNoArgs,
|
||||||
uv_fs_fchmod, fd, mode);
|
uv_fs_fchmod, fd, mode);
|
||||||
} else {
|
} else { // fchmod(fd, mode, undefined, ctx)
|
||||||
SYNC_CALL(fchmod, 0, fd, mode);
|
CHECK_EQ(argc, 4);
|
||||||
|
fs_req_wrap req_wrap;
|
||||||
|
SyncCall(env, args[3], &req_wrap, "fchmod",
|
||||||
|
uv_fs_fchmod, fd, mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,3 +729,23 @@ if (!common.isAIX) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fchmod
|
||||||
|
{
|
||||||
|
const validateError = (err) => {
|
||||||
|
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fchmod');
|
||||||
|
assert.strictEqual(err.errno, uv.UV_EBADF);
|
||||||
|
assert.strictEqual(err.code, 'EBADF');
|
||||||
|
assert.strictEqual(err.syscall, 'fchmod');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
common.runWithInvalidFD((fd) => {
|
||||||
|
fs.fchmod(fd, 0o666, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.fchmodSync(fd, 0o666),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user