Skip to content

Commit

Permalink
fixup! fs: improve error performance for fsyncSync
Browse files Browse the repository at this point in the history
  • Loading branch information
pluris committed Sep 26, 2023
1 parent fb0eeb8 commit e0702cf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions benchmark/fs/bench-fsyncSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function main({ n, type }) {
fd = fs.openSync(tmpfile, 'r', 0o666);
break;
case 'non-existing':
fd = 0;
fd = 1 << 30;
break;
default:
new Error('Invalid type');
Expand All @@ -36,7 +36,7 @@ function main({ n, type }) {
}
}

if (fd !== 0) fs.closeSync(fd);

bench.end(n);

if (type === 'existing') fs.closeSync(fd);
}
1 change: 0 additions & 1 deletion lib/internal/fs/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function close(fd) {
}

function fsync(fd) {
fd = getValidatedFd(fd);
return binding.fsyncSync(fd);
}

Expand Down
4 changes: 3 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1648,14 +1648,16 @@ static void FsyncSync(const FunctionCallbackInfo<Value>& args) {
CHECK_GE(argc, 1);

CHECK(args[0]->IsInt32());

const int fd = args[0].As<Int32>()->Value();
CHECK_GE(fd, 0);

uv_fs_t 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", nullptr);
return env->ThrowUVException(err, "fsync");
}
}

Expand Down
8 changes: 5 additions & 3 deletions typings/internalBinding/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ declare namespace InternalFSBinding {
function fstat(fd: number, useBigint: boolean, usePromises: typeof kUsePromises): Promise<Float64Array | BigUint64Array>;
function fstat(fd: number, useBigint: true, usePromises: typeof kUsePromises): Promise<BigUint64Array>;
function fstat(fd: number, useBigint: false, usePromises: typeof kUsePromises): Promise<Float64Array>;
function fsync(fd: number): void;

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, req: FSReqCallback): void;
function fsyncSync(fd: number, req: undefined, ctx: FSSyncContext): void;
function fsyncSync(fd: number, usePromises: typeof kUsePromises): Promise<void>;

function ftruncate(fd: number, len: number, req: FSReqCallback): void;
function ftruncate(fd: number, len: number, req: undefined, ctx: FSSyncContext): void;
Expand Down Expand Up @@ -243,6 +244,7 @@ export interface FsBinding {
fdatasync: typeof InternalFSBinding.fdatasync;
fstat: typeof InternalFSBinding.fstat;
fsync: typeof InternalFSBinding.fsync;
fsyncSync: typeof InternalFSBinding.fsyncSync;
ftruncate: typeof InternalFSBinding.ftruncate;
futimes: typeof InternalFSBinding.futimes;
internalModuleReadJSON: typeof InternalFSBinding.internalModuleReadJSON;
Expand Down

0 comments on commit e0702cf

Please sign in to comment.