0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 13:09:21 +01:00

fs: fix getDirent().parentPath when type is UV_DIRENT_UNKNOWN

PR-URL: https://github.com/nodejs/node/pull/55553
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Livia Medeiros 2024-11-17 08:23:58 +09:00 committed by GitHub
parent 293386626a
commit c91ce2120c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -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));

View File

@ -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);
},
));
}
@ -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);
},
));
}