fs: throw errors from fs.fdatasyncSync 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
b3a7df7c6d
commit
f5e287ba20
@ -1029,7 +1029,11 @@ fs.fdatasync = function(fd, callback) {
|
|||||||
|
|
||||||
fs.fdatasyncSync = function(fd) {
|
fs.fdatasyncSync = function(fd) {
|
||||||
validateUint32(fd, 'fd');
|
validateUint32(fd, 'fd');
|
||||||
return binding.fdatasync(fd);
|
const ctx = {};
|
||||||
|
binding.fdatasync(fd, undefined, ctx);
|
||||||
|
if (ctx.errno !== undefined) {
|
||||||
|
throw new errors.uvException(ctx);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.fsync = function(fd, callback) {
|
fs.fsync = function(fd, callback) {
|
||||||
|
@ -735,16 +735,21 @@ static void FTruncate(const FunctionCallbackInfo<Value>& args) {
|
|||||||
static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
|
static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
|
|
||||||
|
const int argc = args.Length();
|
||||||
|
CHECK_GE(argc, 2);
|
||||||
|
|
||||||
CHECK(args[0]->IsInt32());
|
CHECK(args[0]->IsInt32());
|
||||||
|
const int fd = args[0]->As<Int32>()->Value();
|
||||||
|
|
||||||
int fd = args[0]->Int32Value();
|
if (args[1]->IsObject()) { // fdatasync(fd, req)
|
||||||
|
CHECK_EQ(argc, 2);
|
||||||
if (args[1]->IsObject()) {
|
|
||||||
CHECK_EQ(args.Length(), 2);
|
|
||||||
AsyncCall(env, args, "fdatasync", UTF8, AfterNoArgs,
|
AsyncCall(env, args, "fdatasync", UTF8, AfterNoArgs,
|
||||||
uv_fs_fdatasync, fd);
|
uv_fs_fdatasync, fd);
|
||||||
} else {
|
} else { // fdatasync(fd, undefined, ctx)
|
||||||
SYNC_CALL(fdatasync, 0, fd)
|
CHECK_EQ(argc, 3);
|
||||||
|
fs_req_wrap req_wrap;
|
||||||
|
SyncCall(env, args[2], &req_wrap, "fdatasync",
|
||||||
|
uv_fs_fdatasync, fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,3 +482,24 @@ function re(literals, ...values) {
|
|||||||
validateError
|
validateError
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fdatasync
|
||||||
|
{
|
||||||
|
const validateError = (err) => {
|
||||||
|
assert.strictEqual(err.message, 'EBADF: bad file descriptor, fdatasync');
|
||||||
|
assert.strictEqual(err.errno, uv.UV_EBADF);
|
||||||
|
assert.strictEqual(err.code, 'EBADF');
|
||||||
|
assert.strictEqual(err.syscall, 'fdatasync');
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fd = fs.openSync(existingFile, 'r');
|
||||||
|
fs.closeSync(fd);
|
||||||
|
|
||||||
|
fs.fdatasync(fd, common.mustCall(validateError));
|
||||||
|
|
||||||
|
assert.throws(
|
||||||
|
() => fs.fdatasyncSync(fd),
|
||||||
|
validateError
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user