@@ -1702,6 +1702,27 @@ static void Unlink(const FunctionCallbackInfo<Value>& args) {
17021702 }
17031703}
17041704
1705+ static void UnlinkSync (const FunctionCallbackInfo<Value>& args) {
1706+ Environment* env = Environment::GetCurrent (args);
1707+
1708+ const int argc = args.Length ();
1709+ CHECK_GE (argc, 1 );
1710+
1711+ BufferValue path (env->isolate (), args[0 ]);
1712+ CHECK_NOT_NULL (*path);
1713+ THROW_IF_INSUFFICIENT_PERMISSIONS (
1714+ env, permission::PermissionScope::kFileSystemWrite , path.ToStringView ());
1715+
1716+ uv_fs_t req;
1717+ auto make = OnScopeLeave ([&req]() { uv_fs_req_cleanup (&req); });
1718+ FS_SYNC_TRACE_BEGIN (unlink);
1719+ int err = uv_fs_unlink (nullptr , &req, *path, nullptr );
1720+ FS_SYNC_TRACE_END (unlink);
1721+ if (err < 0 ) {
1722+ return env->ThrowUVException (err, " unlink" , nullptr , *path);
1723+ }
1724+ }
1725+
17051726static void RMDir (const FunctionCallbackInfo<Value>& args) {
17061727 Environment* env = Environment::GetCurrent (args);
17071728
@@ -3425,6 +3446,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
34253446 SetMethod (isolate, target, " symlink" , Symlink);
34263447 SetMethod (isolate, target, " readlink" , ReadLink);
34273448 SetMethod (isolate, target, " unlink" , Unlink);
3449+ SetMethod (isolate, target, " unlinkSync" , UnlinkSync);
34283450 SetMethod (isolate, target, " writeBuffer" , WriteBuffer);
34293451 SetMethod (isolate, target, " writeBuffers" , WriteBuffers);
34303452 SetMethod (isolate, target, " writeString" , WriteString);
@@ -3550,6 +3572,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
35503572 registry->Register (Symlink);
35513573 registry->Register (ReadLink);
35523574 registry->Register (Unlink);
3575+ registry->Register (UnlinkSync);
35533576 registry->Register (WriteBuffer);
35543577 registry->Register (WriteBuffers);
35553578 registry->Register (WriteString);
0 commit comments