Skip to content

Commit 0c36c6e

Browse files
sonnyinjae-kim
authored andcommitted
fs: fix missing file name with withFileTypes option of readdir
The issue was caused by a modification in PR nodejs#51021, which included changes to the documentation for parentPath and modifications to display the file path. I have retained the content related to the documentation and removed the filepath part. Fixes: nodejs#52441 Co-authored-by: injae-kim <[email protected]>
1 parent 0092358 commit 0c36c6e

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

lib/internal/fs/dir.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ class Dir {
155155
path,
156156
result[i],
157157
result[i + 1],
158-
true, // Quirk to not introduce a breaking change.
159158
),
160159
);
161160
}

lib/internal/fs/utils.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ function assertEncoding(encoding) {
161161
}
162162

163163
class Dirent {
164-
constructor(name, type, path, filepath = path && join(path, name)) {
164+
constructor(name, type, path) {
165165
this.name = name;
166166
this.parentPath = path;
167-
this.path = filepath;
167+
this.path = path;
168168
this[kType] = type;
169169
}
170170

@@ -198,8 +198,8 @@ class Dirent {
198198
}
199199

200200
class DirentFromStats extends Dirent {
201-
constructor(name, stats, path, filepath) {
202-
super(name, null, path, filepath);
201+
constructor(name, stats, path) {
202+
super(name, null, path);
203203
this[kStats] = stats;
204204
}
205205
}
@@ -269,7 +269,7 @@ function getDirents(path, { 0: names, 1: types }, callback) {
269269
callback(err);
270270
return;
271271
}
272-
names[idx] = new DirentFromStats(name, stats, path, filepath);
272+
names[idx] = new DirentFromStats(name, stats, path);
273273
if (--toFinish === 0) {
274274
callback(null, names);
275275
}
@@ -305,21 +305,17 @@ function getDirent(path, name, type, callback) {
305305
callback(err);
306306
return;
307307
}
308-
callback(null, new DirentFromStats(name, stats, path, filepath));
308+
callback(null, new DirentFromStats(name, stats, path));
309309
});
310310
} else {
311311
callback(null, new Dirent(name, type, path));
312312
}
313313
} else if (type === UV_DIRENT_UNKNOWN) {
314314
const filepath = join(path, name);
315315
const stats = lazyLoadFs().lstatSync(filepath);
316-
// callback === true: Quirk to not introduce a breaking change.
317-
return new DirentFromStats(name, stats, path, callback === true ? filepath : path);
318-
} else if (callback === true) {
319-
// callback === true: Quirk to not introduce a breaking change.
320-
return new Dirent(name, type, path);
316+
return new DirentFromStats(name, stats, path);
321317
} else {
322-
return new Dirent(name, type, path, path);
318+
return new Dirent(name, type, path);
323319
}
324320
}
325321

test/parallel/test-fs-opendir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const invalidCallbackObj = {
5151
return { name: dirent.name, path: dirent.path, parentPath: dirent.parentPath, toString() { return dirent.name; } };
5252
}).sort();
5353
assert.deepStrictEqual(entries.map((d) => d.name), files);
54-
assert.deepStrictEqual(entries.map((d) => d.path), files.map((name) => path.join(testDir, name)));
54+
assert.deepStrictEqual(entries.map((d) => d.path), Array(entries.length).fill(testDir));
5555
assert.deepStrictEqual(entries.map((d) => d.parentPath), Array(entries.length).fill(testDir));
5656

5757
// dir.read should return null when no more entries exist

0 commit comments

Comments
 (0)