@@ -116,6 +116,24 @@ inline int64_t GetOffset(Local<Value> value) {
116
116
return IsSafeJsInt (value) ? value.As <Integer>()->Value () : -1 ;
117
117
}
118
118
119
+ inline int GetValidatedFd (Environment* env, Local<Value> value) {
120
+ if (!value->IsInt32 ()) {
121
+ env->isolate ()->ThrowException (ERR_INVALID_ARG_TYPE (
122
+ env->isolate (), " Invalid argument. The fd must be int32." ));
123
+ return 1 << 30 ;
124
+ }
125
+
126
+ const int fd = value.As <Int32>()->Value ();
127
+
128
+ if (fd < 0 || fd > INT32_MAX) {
129
+ env->isolate ()->ThrowException (ERR_OUT_OF_RANGE (
130
+ env->isolate (), " It must be >= 0 && <= INT32_MAX. Received %d" , fd));
131
+ return 1 << 30 ;
132
+ }
133
+
134
+ return fd;
135
+ }
136
+
119
137
static const char * get_fs_func_name_by_type (uv_fs_type req_type) {
120
138
switch (req_type) {
121
139
#define FS_TYPE_TO_NAME (type, name ) \
@@ -1520,6 +1538,24 @@ static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
1520
1538
}
1521
1539
}
1522
1540
1541
+ static void FdatasyncSync (const FunctionCallbackInfo<Value>& args) {
1542
+ Environment* env = Environment::GetCurrent (args);
1543
+
1544
+ CHECK_EQ (args.Length (), 1 );
1545
+
1546
+ const int fd = GetValidatedFd (env, args[0 ]);
1547
+ if (fd == (1 << 30 )) return ;
1548
+
1549
+ uv_fs_t req;
1550
+ auto make = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
1551
+ FS_SYNC_TRACE_BEGIN (fdatasync);
1552
+ int err = uv_fs_fdatasync (nullptr , &req, fd, nullptr );
1553
+ FS_SYNC_TRACE_END (fdatasync);
1554
+ if (err < 0 ) {
1555
+ return env->ThrowUVException (err, " fdatasync" );
1556
+ }
1557
+ }
1558
+
1523
1559
static void Fsync (const FunctionCallbackInfo<Value>& args) {
1524
1560
Environment* env = Environment::GetCurrent (args);
1525
1561
@@ -3218,6 +3254,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
3218
3254
SetMethod (isolate, target, " readFileUtf8" , ReadFileUtf8);
3219
3255
SetMethod (isolate, target, " readBuffers" , ReadBuffers);
3220
3256
SetMethod (isolate, target, " fdatasync" , Fdatasync);
3257
+ SetMethod (isolate, target, " fdatasyncSync" , FdatasyncSync);
3221
3258
SetMethod (isolate, target, " fsync" , Fsync);
3222
3259
SetMethod (isolate, target, " rename" , Rename);
3223
3260
SetMethod (isolate, target, " ftruncate" , FTruncate);
@@ -3337,6 +3374,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
3337
3374
registry->Register (ReadFileUtf8);
3338
3375
registry->Register (ReadBuffers);
3339
3376
registry->Register (Fdatasync);
3377
+ registry->Register (FdatasyncSync);
3340
3378
registry->Register (Fsync);
3341
3379
registry->Register (Rename);
3342
3380
registry->Register (FTruncate);
0 commit comments