@@ -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 ) \
@@ -1618,6 +1636,24 @@ static void Fdatasync(const FunctionCallbackInfo<Value>& args) {
1618
1636
}
1619
1637
}
1620
1638
1639
+ static void FdatasyncSync (const FunctionCallbackInfo<Value>& args) {
1640
+ Environment* env = Environment::GetCurrent (args);
1641
+
1642
+ CHECK_EQ (args.Length (), 1 );
1643
+
1644
+ const int fd = GetValidatedFd (env, args[0 ]);
1645
+ if (fd == (1 << 30 )) return ;
1646
+
1647
+ uv_fs_t req;
1648
+ auto make = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
1649
+ FS_SYNC_TRACE_BEGIN (fdatasync);
1650
+ int err = uv_fs_fdatasync (nullptr , &req, fd, nullptr );
1651
+ FS_SYNC_TRACE_END (fdatasync);
1652
+ if (err < 0 ) {
1653
+ return env->ThrowUVException (err, " fdatasync" );
1654
+ }
1655
+ }
1656
+
1621
1657
static void Fsync (const FunctionCallbackInfo<Value>& args) {
1622
1658
Environment* env = Environment::GetCurrent (args);
1623
1659
@@ -3393,6 +3429,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
3393
3429
SetMethod (isolate, target, " readFileUtf8" , ReadFileUtf8);
3394
3430
SetMethod (isolate, target, " readBuffers" , ReadBuffers);
3395
3431
SetMethod (isolate, target, " fdatasync" , Fdatasync);
3432
+ SetMethod (isolate, target, " fdatasyncSync" , FdatasyncSync);
3396
3433
SetMethod (isolate, target, " fsync" , Fsync);
3397
3434
SetMethod (isolate, target, " rename" , Rename);
3398
3435
SetMethod (isolate, target, " ftruncate" , FTruncate);
@@ -3519,6 +3556,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
3519
3556
registry->Register (ReadFileUtf8);
3520
3557
registry->Register (ReadBuffers);
3521
3558
registry->Register (Fdatasync);
3559
+ registry->Register (FdatasyncSync);
3522
3560
registry->Register (Fsync);
3523
3561
registry->Register (Rename);
3524
3562
registry->Register (FTruncate);
0 commit comments