Skip to content

Commit 05cce21

Browse files
author
pluris
committed
fixup! fs: improve error performance for fsyncSync
1 parent fb0eeb8 commit 05cce21

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

benchmark/fs/bench-fsyncSync.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function main({ n, type }) {
2121
fd = fs.openSync(tmpfile, 'r', 0o666);
2222
break;
2323
case 'non-existing':
24-
fd = 0;
24+
fd = 1 << 30;
2525
break;
2626
default:
2727
new Error('Invalid type');
@@ -36,7 +36,7 @@ function main({ n, type }) {
3636
}
3737
}
3838

39-
if (fd !== 0) fs.closeSync(fd);
40-
4139
bench.end(n);
40+
41+
if (type === 'existing') fs.closeSync(fd);
4242
}

lib/internal/fs/sync.js

-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ function close(fd) {
8989
}
9090

9191
function fsync(fd) {
92-
fd = getValidatedFd(fd);
9392
return binding.fsyncSync(fd);
9493
}
9594

src/node_file.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1648,14 +1648,16 @@ static void FsyncSync(const FunctionCallbackInfo<Value>& args) {
16481648
CHECK_GE(argc, 1);
16491649

16501650
CHECK(args[0]->IsInt32());
1651+
16511652
const int fd = args[0].As<Int32>()->Value();
1653+
CHECK_GE(fd, 0);
16521654

16531655
uv_fs_t req;
16541656
FS_SYNC_TRACE_BEGIN(fsync);
16551657
int err = uv_fs_fsync(nullptr, &req, fd, nullptr);
16561658
FS_SYNC_TRACE_END(fsync);
16571659
if (err < 0) {
1658-
return env->ThrowUVException(err, "fsync", nullptr);
1660+
return env->ThrowUVException(err, "fsync");
16591661
}
16601662
}
16611663

typings/internalBinding/fs.d.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ declare namespace InternalFSBinding {
9494
function fstat(fd: number, useBigint: boolean, usePromises: typeof kUsePromises): Promise<Float64Array | BigUint64Array>;
9595
function fstat(fd: number, useBigint: true, usePromises: typeof kUsePromises): Promise<BigUint64Array>;
9696
function fstat(fd: number, useBigint: false, usePromises: typeof kUsePromises): Promise<Float64Array>;
97+
function fsync(fd: number): void;
9798

98-
function fsync(fd: number, req: FSReqCallback): void;
99-
function fsync(fd: number, req: undefined, ctx: FSSyncContext): void;
100-
function fsync(fd: number, usePromises: typeof kUsePromises): Promise<void>;
99+
function fsyncSync(fd: number, req: FSReqCallback): void;
100+
function fsyncSync(fd: number, req: undefined, ctx: FSSyncContext): void;
101+
function fsyncSync(fd: number, usePromises: typeof kUsePromises): Promise<void>;
101102

102103
function ftruncate(fd: number, len: number, req: FSReqCallback): void;
103104
function ftruncate(fd: number, len: number, req: undefined, ctx: FSSyncContext): void;
@@ -243,6 +244,7 @@ export interface FsBinding {
243244
fdatasync: typeof InternalFSBinding.fdatasync;
244245
fstat: typeof InternalFSBinding.fstat;
245246
fsync: typeof InternalFSBinding.fsync;
247+
fsyncSync: typeof InternalFSBinding.fsyncSync;
246248
ftruncate: typeof InternalFSBinding.ftruncate;
247249
futimes: typeof InternalFSBinding.futimes;
248250
internalModuleReadJSON: typeof InternalFSBinding.internalModuleReadJSON;

0 commit comments

Comments
 (0)