@@ -1667,6 +1667,27 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
16671667 }
16681668}
16691669
1670+ static void UnlinkSync (const FunctionCallbackInfo<Value>& args) {
1671+ Environment* env = Environment::GetCurrent (args);
1672+
1673+ const int argc = args.Length ();
1674+ CHECK_GE (argc, 1 );
1675+
1676+ BufferValue path (env->isolate (), args[0 ]);
1677+ CHECK_NOT_NULL (*path);
1678+ THROW_IF_INSUFFICIENT_PERMISSIONS (
1679+ env, permission::PermissionScope::kFileSystemWrite , path.ToStringView ());
1680+
1681+ uv_fs_t req;
1682+ auto make = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
1683+ FS_SYNC_TRACE_BEGIN (unlink);
1684+ int err = uv_fs_unlink (nullptr , &req, *path, nullptr );
1685+ FS_SYNC_TRACE_END (unlink);
1686+ if (err < 0 ) {
1687+ return env->ThrowUVException (err, " unlink" , nullptr , *path);
1688+ }
1689+ }
1690+
16701691static void RMDir (const FunctionCallbackInfo<Value>& args) {
16711692 Environment* env = Environment::GetCurrent (args);
16721693
@@ -3390,6 +3411,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
33903411 SetMethod (isolate, target, " symlink" , Symlink);
33913412 SetMethod (isolate, target, " readlink" , ReadLink);
33923413 SetMethod (isolate, target, " unlink" , Unlink);
3414+ SetMethod (isolate, target, " unlinkSync" , UnlinkSync);
33933415 SetMethod (isolate, target, " writeBuffer" , WriteBuffer);
33943416 SetMethod (isolate, target, " writeBuffers" , WriteBuffers);
33953417 SetMethod (isolate, target, " writeString" , WriteString);
@@ -3515,6 +3537,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
35153537 registry->Register (Symlink);
35163538 registry->Register (ReadLink);
35173539 registry->Register (Unlink);
3540+ registry->Register (UnlinkSync);
35183541 registry->Register (WriteBuffer);
35193542 registry->Register (WriteBuffers);
35203543 registry->Register (WriteString);
0 commit comments