GeezerVison is showing github.com — fs: fix readdir and opendir recursive with unknown file types · nodejs/node@db3fc6d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/dir.js +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -152,7 +152,7 @@ class Dir { | 152 | 152 | ArrayPrototypePush( | 153 | 153 | this[kDirBufferedEntries], | 154 | 154 | getDirent( | 155 | | - pathModule.join(path, result[i]), | | 155 | + path, | 156 | 156 | result[i], | 157 | 157 | result[i + 1], | 158 | 158 | ), | @@ -161,9 +161,10 @@ class Dir { | 161 | 161 | } | 162 | 162 |
| 163 | 163 | readSyncRecursive(dirent) { | 164 | | - const ctx = { path: dirent.path }; | | 164 | + const path = pathModule.join(dirent.path, dirent.name); | | 165 | + const ctx = { path }; | 165 | 166 | const handle = dirBinding.opendir( | 166 | | - pathModule.toNamespacedPath(dirent.path), | | 167 | + pathModule.toNamespacedPath(path), | 167 | 168 | this[kDirOptions].encoding, | 168 | 169 | undefined, | 169 | 170 | ctx, | @@ -177,7 +178,7 @@ class Dir { | 177 | 178 | ); | 178 | 179 |
| 179 | 180 | if (result) { | 180 | | - this.processReadResult(dirent.path, result); | | 181 | + this.processReadResult(path, result); | 181 | 182 | } | 182 | 183 |
| 183 | 184 | handle.close(undefined, ctx); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/utils.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -234,7 +234,7 @@ function join(path, name) { | 234 | 234 | } | 235 | 235 |
| 236 | 236 | if (typeof path === 'string' && typeof name === 'string') { | 237 | | - return pathModule.basename(path) === name ? path : pathModule.join(path, name); | | 237 | + return pathModule.join(path, name); | 238 | 238 | } | 239 | 239 |
| 240 | 240 | if (isUint8Array(path) && isUint8Array(name)) { | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-fs-opendir-recursive.js +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,7 +10,7 @@ const tmpdir = require('../common/tmpdir'); | 10 | 10 | const testDir = tmpdir.path; | 11 | 11 |
| 12 | 12 | const fileStructure = [ | 13 | | - [ 'a', [ 'foo', 'bar' ] ], | | 13 | + [ 'a', [ 'a', 'foo', 'bar' ] ], | 14 | 14 | [ 'b', [ 'foo', 'bar' ] ], | 15 | 15 | [ 'c', [ 'foo', 'bar' ] ], | 16 | 16 | [ 'd', [ 'foo', 'bar' ] ], | @@ -91,7 +91,7 @@ fs.symlinkSync(symlinkTargetFile, pathModule.join(symlinksRootPath, 'symlink-src | 91 | 91 | fs.symlinkSync(symlinkTargetDir, pathModule.join(symlinksRootPath, 'symlink-src-dir')); | 92 | 92 |
| 93 | 93 | const expected = [ | 94 | | - 'a', 'a/bar', 'a/foo', 'aa', 'aa/bar', 'aa/foo', | | 94 | + 'a', 'a/a', 'a/bar', 'a/foo', 'aa', 'aa/bar', 'aa/foo', | 95 | 95 | 'abc', 'abc/def', 'abc/def/bar', 'abc/def/foo', 'abc/ghi', 'abc/ghi/bar', 'abc/ghi/foo', | 96 | 96 | 'b', 'b/bar', 'b/foo', 'bb', 'bb/bar', 'bb/foo', | 97 | 97 | 'c', 'c/bar', 'c/foo', 'cc', 'cc/bar', 'cc/foo', | @@ -128,15 +128,18 @@ for (let i = 0; i < expected.length; i++) { | 128 | 128 | } | 129 | 129 |
| 130 | 130 | function getDirentPath(dirent) { | 131 | | - return pathModule.relative(testDir, dirent.path); | | 131 | + return pathModule.relative(testDir, pathModule.join(dirent.path, dirent.name)); | 132 | 132 | } | 133 | 133 |
| 134 | 134 | function assertDirents(dirents) { | 135 | 135 | dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1)); | 136 | | - for (const [i, dirent] of dirents.entries()) { | 137 | | - assert(dirent instanceof fs.Dirent); | 138 | | - assert.strictEqual(getDirentPath(dirent), expected[i]); | 139 | | - } | | 136 | + assert.deepStrictEqual( | | 137 | + dirents.map((dirent) => { | | 138 | + assert(dirent instanceof fs.Dirent); | | 139 | + return getDirentPath(dirent); | | 140 | + }), | | 141 | + expected | | 142 | + ); | 140 | 143 | } | 141 | 144 |
| 142 | 145 | function processDirSync(dir) { | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-fs-readdir-recursive.js +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ const tmpdir = require('../common/tmpdir'); | 9 | 9 | const readdirDir = tmpdir.path; | 10 | 10 |
| 11 | 11 | const fileStructure = [ | 12 | | - [ 'a', [ 'foo', 'bar' ] ], | | 12 | + [ 'a', [ 'a', 'foo', 'bar' ] ], | 13 | 13 | [ 'b', [ 'foo', 'bar' ] ], | 14 | 14 | [ 'c', [ 'foo', 'bar' ] ], | 15 | 15 | [ 'd', [ 'foo', 'bar' ] ], | @@ -90,7 +90,7 @@ fs.symlinkSync(symlinkTargetFile, pathModule.join(symlinksRootPath, 'symlink-src | 90 | 90 | fs.symlinkSync(symlinkTargetDir, pathModule.join(symlinksRootPath, 'symlink-src-dir')); | 91 | 91 |
| 92 | 92 | const expected = [ | 93 | | - 'a', 'a/bar', 'a/foo', 'aa', 'aa/bar', 'aa/foo', | | 93 | + 'a', 'a/a', 'a/bar', 'a/foo', 'aa', 'aa/bar', 'aa/foo', | 94 | 94 | 'abc', 'abc/def', 'abc/def/bar', 'abc/def/foo', 'abc/ghi', 'abc/ghi/bar', 'abc/ghi/foo', | 95 | 95 | 'b', 'b/bar', 'b/foo', 'bb', 'bb/bar', 'bb/foo', | 96 | 96 | 'c', 'c/bar', 'c/foo', 'cc', 'cc/bar', 'cc/foo', | @@ -133,11 +133,14 @@ function getDirentPath(dirent) { | 133 | 133 | function assertDirents(dirents) { | 134 | 134 | assert.strictEqual(dirents.length, expected.length); | 135 | 135 | dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1)); | 136 | | - for (const [i, dirent] of dirents.entries()) { | 137 | | - assert(dirent instanceof fs.Dirent); | 138 | | - assert.notStrictEqual(dirent.name, undefined); | 139 | | - assert.strictEqual(getDirentPath(dirent), expected[i]); | 140 | | - } | | 136 | + assert.deepStrictEqual( | | 137 | + dirents.map((dirent) => { | | 138 | + assert(dirent instanceof fs.Dirent); | | 139 | + assert.notStrictEqual(dirent.name, undefined); | | 140 | + return getDirentPath(dirent); | | 141 | + }), | | 142 | + expected | | 143 | + ); | 141 | 144 | } | 142 | 145 |
| 143 | 146 | // readdirSync | |
|