Skip to content

Commit

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

/**
Expand Down
36 changes: 8 additions & 28 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1542,43 +1542,25 @@ static void Fsync(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]);
if (fd == (1 << 30)) return;

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

static void FsyncSync(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(fsync);
int err = uv_fs_fsync(nullptr, &req, fd, nullptr);
FS_SYNC_TRACE_END(fsync);
if (err < 0) {
return env->ThrowUVException(err, "fsync");
}
}

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

Expand Down Expand Up @@ -3255,7 +3237,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
SetMethod(isolate, target, "readBuffers", ReadBuffers);
SetMethod(isolate, target, "fdatasync", Fdatasync);
SetMethod(isolate, target, "fsync", Fsync);
SetMethod(isolate, target, "fsyncSync", FsyncSync);
SetMethod(isolate, target, "rename", Rename);
SetMethod(isolate, target, "ftruncate", FTruncate);
SetMethod(isolate, target, "rmdir", RMDir);
Expand Down Expand Up @@ -3375,7 +3356,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(ReadBuffers);
registry->Register(Fdatasync);
registry->Register(Fsync);
registry->Register(FsyncSync);
registry->Register(Rename);
registry->Register(FTruncate);
registry->Register(RMDir);
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 @@ -98,7 +98,7 @@ declare namespace InternalFSBinding {
function fsync(fd: number, req: FSReqCallback): void;
function fsync(fd: number, req: undefined, ctx: FSSyncContext): void;
function fsync(fd: number, usePromises: typeof kUsePromises): Promise<void>;
function fsyncSync(fd: number): void;
function fsync(fd: number): void;

function ftruncate(fd: number, len: number, req: FSReqCallback): void;
function ftruncate(fd: number, len: number, req: undefined, ctx: FSSyncContext): void;
Expand Down

0 comments on commit 0828da3

Please sign in to comment.