Skip to content

Commit

Permalink
fs: fix getDirent().parentPath when type is UV_DIRENT_UNKNOWN
Browse files Browse the repository at this point in the history
PR-URL: nodejs#55553
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
LiviaMedeiros authored and Ceres6 committed Nov 26, 2024
1 parent 54d5d64 commit 5810419
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function getDirent(path, name, type, callback) {
callback(err);
return;
}
callback(null, new DirentFromStats(name, stats, filepath));
callback(null, new DirentFromStats(name, stats, path));
});
} else {
callback(null, new Dirent(name, type, path));
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-fs-utils-get-dirents.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const filename = 'foo';
common.mustCall((err, dirent) => {
assert.strictEqual(err, null);
assert.strictEqual(dirent.name, filename);
assert.strictEqual(dirent.parentPath, tmpdir.path);
},
));
}
Expand All @@ -100,20 +101,22 @@ const filename = 'foo';
common.mustCall((err, dirent) => {
assert.strictEqual(err, null);
assert.strictEqual(dirent.name, filenameBuffer);
assert.deepStrictEqual(dirent.parentPath, Buffer.from(tmpdir.resolve(`${filename}/`)));
assert.strictEqual(dirent.parentPath, tmpdir.path);
},
));
}
{
// Buffer + Buffer
const filenameBuffer = Buffer.from(filename);
const dirnameBuffer = Buffer.from(tmpdir.path);
getDirent(
Buffer.from(tmpdir.path),
dirnameBuffer,
filenameBuffer,
UV_DIRENT_UNKNOWN,
common.mustCall((err, dirent) => {
assert.strictEqual(err, null);
assert.strictEqual(dirent.name, filenameBuffer);
assert.deepStrictEqual(dirent.parentPath, dirnameBuffer);
},
));
}
Expand Down

0 comments on commit 5810419

Please sign in to comment.