From aff90b3d4d5ffcbf5ffd042142ce8069d14ce3b5 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 15 Jan 2025 23:25:25 +0100 Subject: [PATCH] fixup! src: move package resolver to c++ --- src/node_modules.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/node_modules.cc b/src/node_modules.cc index e905df8bde42fe8..d1c4c2af59c7c68 100644 --- a/src/node_modules.cc +++ b/src/node_modules.cc @@ -105,6 +105,26 @@ const BindingData::PackageConfig* BindingData::GetPackageJSON( PackageConfig package_config{}; package_config.file_path = path; + +#ifdef _AIX + // On AIX, the file read can still succeed even if it's a directory. + // For backporting https://github.com/nodejs/node/pull/50322 to v20.x, + // add the special case back and return early to notify the JS land + // and let it treat it as if the package.json does not exist. + // See https://github.com/libuv/libuv/pull/2025 and + // https://github.com/nodejs/node/pull/48477#issuecomment-1604586650 + uv_fs_t req; + int rc = uv_fs_stat(nullptr, &req, *path, nullptr); + if (rc == 0) { + const uv_stat_t* const s = static_cast(req.ptr); + boo is_dir = ((s->st_mode & S_IFMT) == S_IFDIR); + uv_fs_req_cleanup(&req); + if (is_dir) { + return nullptr; + } + } +#endif + // No need to exclude BOM since simdjson will skip it. if (ReadFileSync(&package_config.raw_json, path.data()) < 0) { return nullptr;