GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: introduce `dirent.parentPath` · nodejs/node@32acafe

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • fs.md
  • lib
    • fs.js
    • internal/fs
      • dir.js
      • utils.js
  • test/parallel
    • test-fs-opendir.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/fs.md‎

Copy file name to clipboardExpand all lines: doc/api/fs.md
+14-1Lines changed: 14 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -6614,6 +6614,19 @@ The file name that this {fs.Dirent} object refers to. The type of this
66146614
value is determined by the `options.encoding` passed to [`fs.readdir()`][] or
66156615
[`fs.readdirSync()`][].
66166616
6617+
#### `dirent.parentPath`
6618+
6619+
<!-- YAML
6620+
added:
6621+
- REPLACEME
6622+
-->
6623+
6624+
> Stability: 1 – Experimental
6625+
6626+
* {string}
6627+
6628+
The path to the parent directory of the file this {fs.Dirent} object refers to.
6629+
66176630
#### `dirent.path`
66186631
66196632
<!-- YAML
@@ -6624,7 +6637,7 @@ added:
66246637
66256638
* {string}
66266639
6627-
The base path that this {fs.Dirent} object refers to.
6640+
Alias for `dirent.parentPath`.
66286641
66296642
### Class: `fs.FSWatcher`
66306643
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ function readdirSyncRecursive(basePath, options) {
14261426
const dirent = getDirent(path, readdirResult[0][i], readdirResult[1][i]);
14271427
ArrayPrototypePush(readdirResults, dirent);
14281428
if (dirent.isDirectory()) {
1429-
ArrayPrototypePush(pathsQueue, pathModule.join(dirent.path, dirent.name));
1429+
ArrayPrototypePush(pathsQueue, pathModule.join(dirent.parentPath, dirent.name));
14301430
}
14311431
}
14321432
} else {
Collapse file

‎lib/internal/fs/dir.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/dir.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class Dir {
161161
}
162162

163163
readSyncRecursive(dirent) {
164-
const path = pathModule.join(dirent.path, dirent.name);
164+
const path = pathModule.join(dirent.parentPath, dirent.name);
165165
const ctx = { path };
166166
const handle = dirBinding.opendir(
167167
pathModule.toNamespacedPath(path),
Collapse file

‎lib/internal/fs/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/utils.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function assertEncoding(encoding) {
165165
class Dirent {
166166
constructor(name, type, path) {
167167
this.name = name;
168+
this.parentPath = path;
168169
this.path = path;
169170
this[kType] = type;
170171
}
Collapse file

‎test/parallel/test-fs-opendir.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-opendir.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ const invalidCallbackObj = {
4848
const entries = files.map(() => {
4949
const dirent = dir.readSync();
5050
assertDirent(dirent);
51-
return dirent.name;
52-
});
53-
assert.deepStrictEqual(files, entries.sort());
51+
return { name: dirent.name, path: dirent.path, parentPath: dirent.parentPath, toString() { return dirent.name; } };
52+
}).sort();
53+
assert.deepStrictEqual(entries.map((d) => d.name), files);
54+
assert.deepStrictEqual(entries.map((d) => d.path), Array(entries.length).fill(testDir));
55+
assert.deepStrictEqual(entries.map((d) => d.parentPath), Array(entries.length).fill(testDir));
5456

5557
// dir.read should return null when no more entries exist
5658
assert.strictEqual(dir.readSync(), null);

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.