Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: fix realpath inode link caching #33945

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const kIoMaxLength = 2 ** 31 - 1;
const {
Map,
MathMax,
Number,
NumberIsSafeInteger,
ObjectCreate,
ObjectDefineProperties,
Expand Down Expand Up @@ -182,7 +183,10 @@ const isFd = isUint32;
function isFileType(stats, fileType) {
// Use stats array directly to avoid creating an fs.Stats instance just for
// our internal use.
return (stats[1/* mode */] & S_IFMT) === fileType;
let mode = stats[1];
if (typeof mode === 'bigint')
mode = Number(mode);
return (mode & S_IFMT) === fileType;
}

function access(path, mode, callback) {
Expand Down Expand Up @@ -1650,7 +1654,7 @@ function realpathSync(p, options) {

const baseLong = pathModule.toNamespacedPath(base);
const ctx = { path: base };
const stats = binding.lstat(baseLong, false, undefined, ctx);
const stats = binding.lstat(baseLong, true, undefined, ctx);
handleErrorFromBinding(ctx);

if (!isFileType(stats, S_IFLNK)) {
Expand Down Expand Up @@ -1783,7 +1787,7 @@ function realpath(p, options, callback) {
return process.nextTick(LOOP);
}

return fs.lstat(base, gotStat);
return fs.lstat(base, { bigint: true }, gotStat);
}

function gotStat(err, stats) {
Expand Down