diff --git a/benchmark/fs/bench-unlinkSync.js b/benchmark/fs/bench-unlinkSync.js new file mode 100644 index 00000000000000..8b992198c8d368 --- /dev/null +++ b/benchmark/fs/bench-unlinkSync.js @@ -0,0 +1,43 @@ +'use strict'; + +const common = require('../common'); +const fs = require('fs'); +const tmpdir = require('../../test/common/tmpdir'); +tmpdir.refresh(); + +const bench = common.createBenchmark(main, { + type: ['existing', 'non-existing'], + n: [1e3], +}); + +function main({ n, type }) { + let files; + + switch (type) { + case 'existing': + files = []; + + // Populate tmpdir with mock files + for (let i = 0; i < n; i++) { + const path = tmpdir.resolve(`unlinksync-bench-file-${i}`); + fs.writeFileSync(path, 'bench'); + files.push(path); + } + break; + case 'non-existing': + files = new Array(n).fill(tmpdir.resolve(`.non-existing-file-${Date.now()}`)); + break; + default: + new Error('Invalid type'); + } + + bench.start(); + for (let i = 0; i < n; i++) { + try { + fs.unlinkSync(files[i]); + } catch { + // do nothing + } + } + bench.end(n); +} diff --git a/common.gypi b/common.gypi index 14f05fcf9ccb8d..909d09934a1b25 100644 --- a/common.gypi +++ b/common.gypi @@ -36,7 +36,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.18', + 'v8_embedder_string': '-node.19', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc index e0602edc7e1c6a..e4ca7bfdacb11c 100644 --- a/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc +++ b/deps/v8/src/snapshot/embedded/platform-embedded-file-writer-base.cc @@ -130,7 +130,8 @@ EmbeddedTargetOs ToEmbeddedTargetOs(const char* s) { } std::string string(s); - if (string == "aix") { + // Python 3.9+ on IBM i returns os400 as sys.platform instead of aix + if (string == "aix" || string == "os400") { return EmbeddedTargetOs::kAIX; } else if (string == "chromeos") { return EmbeddedTargetOs::kChromeOS; diff --git a/lib/fs.js b/lib/fs.js index 9b6b61dc8efd42..29f356a57cd22e 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1850,10 +1850,7 @@ function unlink(path, callback) { * @returns {void} */ function unlinkSync(path) { - path = getValidatedPath(path); - const ctx = { path }; - binding.unlink(pathModule.toNamespacedPath(path), undefined, ctx); - handleErrorFromBinding(ctx); + return syncFs.unlink(path); } /** diff --git a/lib/internal/fs/sync.js b/lib/internal/fs/sync.js index 0d4ba90150e186..fbcc2ad2e25b2a 100644 --- a/lib/internal/fs/sync.js +++ b/lib/internal/fs/sync.js @@ -88,6 +88,11 @@ function close(fd) { return binding.closeSync(fd); } +function unlink(path) { + path = pathModule.toNamespacedPath(getValidatedPath(path)); + return binding.unlinkSync(path); +} + module.exports = { readFileUtf8, exists, @@ -97,4 +102,5 @@ module.exports = { statfs, open, close, + unlink, }; diff --git a/src/node_file.cc b/src/node_file.cc index b76eb385295836..aca7ec82101a60 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1667,6 +1667,27 @@ static void Unlink(const FunctionCallbackInfo& args) { } } +static void UnlinkSync(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + + const int argc = args.Length(); + CHECK_GE(argc, 1); + + BufferValue path(env->isolate(), args[0]); + CHECK_NOT_NULL(*path); + THROW_IF_INSUFFICIENT_PERMISSIONS( + env, permission::PermissionScope::kFileSystemWrite, path.ToStringView()); + + uv_fs_t req; + auto make = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); }); + FS_SYNC_TRACE_BEGIN(unlink); + int err = uv_fs_unlink(nullptr, &req, *path, nullptr); + FS_SYNC_TRACE_END(unlink); + if (err < 0) { + return env->ThrowUVException(err, "unlink", nullptr, *path); + } +} + static void RMDir(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -3361,15 +3382,15 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data, Isolate* isolate = isolate_data->isolate(); SetMethod(isolate, target, "access", Access); - SetMethodNoSideEffect(isolate, target, "accessSync", AccessSync); + SetMethod(isolate, target, "accessSync", AccessSync); SetMethod(isolate, target, "close", Close); SetMethod(isolate, target, "closeSync", CloseSync); - SetMethodNoSideEffect(isolate, target, "existsSync", ExistsSync); + SetMethod(isolate, target, "existsSync", ExistsSync); SetMethod(isolate, target, "open", Open); SetMethod(isolate, target, "openSync", OpenSync); SetMethod(isolate, target, "openFileHandle", OpenFileHandle); SetMethod(isolate, target, "read", Read); - SetMethodNoSideEffect(isolate, target, "readFileUtf8", ReadFileUtf8); + SetMethod(isolate, target, "readFileUtf8", ReadFileUtf8); SetMethod(isolate, target, "readBuffers", ReadBuffers); SetMethod(isolate, target, "fdatasync", Fdatasync); SetMethod(isolate, target, "fsync", Fsync); @@ -3390,12 +3411,13 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data, SetMethod(isolate, target, "symlink", Symlink); SetMethod(isolate, target, "readlink", ReadLink); SetMethod(isolate, target, "unlink", Unlink); + SetMethod(isolate, target, "unlinkSync", UnlinkSync); SetMethod(isolate, target, "writeBuffer", WriteBuffer); SetMethod(isolate, target, "writeBuffers", WriteBuffers); SetMethod(isolate, target, "writeString", WriteString); SetMethod(isolate, target, "realpath", RealPath); SetMethod(isolate, target, "copyFile", CopyFile); - SetMethodNoSideEffect(isolate, target, "copyFileSync", CopyFileSync); + SetMethod(isolate, target, "copyFileSync", CopyFileSync); SetMethod(isolate, target, "chmod", Chmod); SetMethod(isolate, target, "fchmod", FChmod); @@ -3515,6 +3537,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(Symlink); registry->Register(ReadLink); registry->Register(Unlink); + registry->Register(UnlinkSync); registry->Register(WriteBuffer); registry->Register(WriteBuffers); registry->Register(WriteString); diff --git a/test/parallel/test-os.js b/test/parallel/test-os.js index f0f55fbe261946..d82f2ece3159a6 100644 --- a/test/parallel/test-os.js +++ b/test/parallel/test-os.js @@ -81,6 +81,12 @@ const hostname = os.hostname(); is.string(hostname); assert.ok(hostname.length > 0); +const DUMMY_PRIORITY = 10; +os.setPriority(DUMMY_PRIORITY); +const priority = os.getPriority(); +is.number(priority); +assert.strictEqual(priority, DUMMY_PRIORITY); + // On IBMi, os.uptime() returns 'undefined' if (!common.isIBMi) { const uptime = os.uptime();