Skip to content

Commit c91ce21

Browse files
fs: fix getDirent().parentPath when type is UV_DIRENT_UNKNOWN
PR-URL: #55553 Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 2933866 commit c91ce21

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/internal/fs/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function getDirent(path, name, type, callback) {
301301
callback(err);
302302
return;
303303
}
304-
callback(null, new DirentFromStats(name, stats, filepath));
304+
callback(null, new DirentFromStats(name, stats, path));
305305
});
306306
} else {
307307
callback(null, new Dirent(name, type, path));

test/parallel/test-fs-utils-get-dirents.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const filename = 'foo';
7575
common.mustCall((err, dirent) => {
7676
assert.strictEqual(err, null);
7777
assert.strictEqual(dirent.name, filename);
78+
assert.strictEqual(dirent.parentPath, tmpdir.path);
7879
},
7980
));
8081
}
@@ -100,20 +101,22 @@ const filename = 'foo';
100101
common.mustCall((err, dirent) => {
101102
assert.strictEqual(err, null);
102103
assert.strictEqual(dirent.name, filenameBuffer);
103-
assert.deepStrictEqual(dirent.parentPath, Buffer.from(tmpdir.resolve(`${filename}/`)));
104+
assert.strictEqual(dirent.parentPath, tmpdir.path);
104105
},
105106
));
106107
}
107108
{
108109
// Buffer + Buffer
109110
const filenameBuffer = Buffer.from(filename);
111+
const dirnameBuffer = Buffer.from(tmpdir.path);
110112
getDirent(
111-
Buffer.from(tmpdir.path),
113+
dirnameBuffer,
112114
filenameBuffer,
113115
UV_DIRENT_UNKNOWN,
114116
common.mustCall((err, dirent) => {
115117
assert.strictEqual(err, null);
116118
assert.strictEqual(dirent.name, filenameBuffer);
119+
assert.deepStrictEqual(dirent.parentPath, dirnameBuffer);
117120
},
118121
));
119122
}

0 commit comments

Comments
 (0)