Skip to content

Commit

Permalink
apply #49913
Browse files Browse the repository at this point in the history
  • Loading branch information
pluris committed Oct 1, 2023
1 parent 70a8931 commit 78b27c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ function fdatasync(fd, callback) {
* @returns {void}
*/
function fdatasyncSync(fd) {
syncFs.fdatasync(fd);
return binding.fdatasync(fd);
}

/**
Expand Down
37 changes: 8 additions & 29 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1519,43 +1519,24 @@ static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

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

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

FSReqBase* req_wrap_async = GetReqWrap(args, 1);
if (req_wrap_async != nullptr) {
if (argc > 1) { // fdatasync(fd, req)
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
CHECK_NOT_NULL(req_wrap_async);
FS_ASYNC_TRACE_BEGIN0(UV_FS_FDATASYNC, req_wrap_async)
AsyncCall(env, req_wrap_async, args, "fdatasync", UTF8, AfterNoArgs,
uv_fs_fdatasync, fd);
} else {
CHECK_EQ(argc, 3);
FSReqWrapSync req_wrap_sync;
} else { // fdatasync(fd)
FSReqWrapSync req_wrap_sync("fdatasync");
FS_SYNC_TRACE_BEGIN(fdatasync);
SyncCall(env, args[2], &req_wrap_sync, "fdatasync", uv_fs_fdatasync, fd);
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_fdatasync, fd);
FS_SYNC_TRACE_END(fdatasync);
}
}

static void FdatasyncSync(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK_EQ(args.Length(), 1);

const int fd = GetValidatedFd(env, args[0]);
if (fd == (1 << 30)) return;

uv_fs_t req;
auto make = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
FS_SYNC_TRACE_BEGIN(fdatasync);
int err = uv_fs_fdatasync(nullptr, &req, fd, nullptr);
FS_SYNC_TRACE_END(fdatasync);
if (err < 0) {
return env->ThrowUVException(err, "fdatasync");
}
}

static void Fsync(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

Expand Down Expand Up @@ -3254,7 +3235,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
SetMethod(isolate, target, "readFileUtf8", ReadFileUtf8);
SetMethod(isolate, target, "readBuffers", ReadBuffers);
SetMethod(isolate, target, "fdatasync", Fdatasync);
SetMethod(isolate, target, "fdatasyncSync", FdatasyncSync);
SetMethod(isolate, target, "fsync", Fsync);
SetMethod(isolate, target, "rename", Rename);
SetMethod(isolate, target, "ftruncate", FTruncate);
Expand Down Expand Up @@ -3374,7 +3354,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(ReadFileUtf8);
registry->Register(ReadBuffers);
registry->Register(Fdatasync);
registry->Register(FdatasyncSync);
registry->Register(Fsync);
registry->Register(Rename);
registry->Register(FTruncate);
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ declare namespace InternalFSBinding {
function fdatasync(fd: number, req: FSReqCallback): void;
function fdatasync(fd: number, req: undefined, ctx: FSSyncContext): void;
function fdatasync(fd: number, usePromises: typeof kUsePromises): Promise<void>;
function fdatasyncSync(fd: number): void;
function fdatasync(fd: number): void;

function fstat(fd: number, useBigint: boolean, req: FSReqCallback<Float64Array | BigUint64Array>): void;
function fstat(fd: number, useBigint: true, req: FSReqCallback<BigUint64Array>): void;
Expand Down

0 comments on commit 78b27c0

Please sign in to comment.