Skip to content

Commit 9156c84

Browse files
authored
fix: add parentPath to Dirent (#1058)
* #735 - add parentPath property to Dirent * #735 - fix tests for parentPath property * #735 - use Dirent parentPath instead of path in Volume
1 parent a6ec0bf commit 9156c84

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/Dirent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ export class Dirent implements IDirent {
1616
dirent.name = strToEncoding(link.getName(), encoding);
1717
dirent.mode = mode;
1818
dirent.path = link.getParentPath();
19+
dirent.parentPath = dirent.path;
1920

2021
return dirent;
2122
}
2223

2324
name: TDataOut = '';
2425
path = '';
26+
parentPath = '';
2527
private mode: number = 0;
2628

2729
private _checkModeProperty(property: number): boolean {

src/__tests__/volume/readdirSync.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ describe('readdirSync()', () => {
6767
return { ...dirent };
6868
});
6969
expect(mapped).toEqual([
70-
{ mode: 33206, name: 'af', path: '/x' },
71-
{ mode: 16895, name: 'b', path: '/x' },
72-
{ mode: 16895, name: 'c', path: '/x' },
70+
{ mode: 33206, name: 'af', path: '/x', parentPath: '/x' },
71+
{ mode: 16895, name: 'b', path: '/x', parentPath: '/x' },
72+
{ mode: 16895, name: 'c', path: '/x', parentPath: '/x' },
7373
]);
7474
});
7575

@@ -105,16 +105,16 @@ describe('readdirSync()', () => {
105105
})
106106
.sort((a, b) => a.path.localeCompare(b.path));
107107
expect(mapped).toEqual([
108-
{ mode: 33206, name: 'af1', path: '/z' },
109-
{ mode: 33206, name: 'af2', path: '/z' },
110-
{ mode: 16895, name: 'b', path: '/z' },
111-
{ mode: 16895, name: 'c', path: '/z' },
112-
{ mode: 33206, name: 'bf1', path: '/z/b' },
113-
{ mode: 33206, name: 'bf2', path: '/z/b' },
114-
{ mode: 16895, name: 'c', path: '/z/c' },
115-
{ mode: 33206, name: '.cf0', path: '/z/c/c' },
116-
{ mode: 33206, name: 'cf1', path: '/z/c/c' },
117-
{ mode: 33206, name: 'cf2', path: '/z/c/c' },
108+
{ mode: 33206, name: 'af1', path: '/z', parentPath: '/z' },
109+
{ mode: 33206, name: 'af2', path: '/z', parentPath: '/z' },
110+
{ mode: 16895, name: 'b', path: '/z', parentPath: '/z' },
111+
{ mode: 16895, name: 'c', path: '/z', parentPath: '/z' },
112+
{ mode: 33206, name: 'bf1', path: '/z/b', parentPath: '/z/b' },
113+
{ mode: 33206, name: 'bf2', path: '/z/b', parentPath: '/z/b' },
114+
{ mode: 16895, name: 'c', path: '/z/c', parentPath: '/z/c' },
115+
{ mode: 33206, name: '.cf0', path: '/z/c/c', parentPath: '/z/c/c' },
116+
{ mode: 33206, name: 'cf1', path: '/z/c/c', parentPath: '/z/c/c' },
117+
{ mode: 33206, name: 'cf2', path: '/z/c/c', parentPath: '/z/c/c' },
118118
]);
119119
});
120120
});

src/volume.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ export class Volume implements FsCallbackApi, FsSynchronousApi {
14991499

15001500
return list.map(dirent => {
15011501
if (options.recursive) {
1502-
let fullPath = pathModule.join(dirent.path, dirent.name.toString());
1502+
let fullPath = pathModule.join(dirent.parentPath, dirent.name.toString());
15031503
if (isWin) {
15041504
fullPath = fullPath.replace(/\\/g, '/');
15051505
}

0 commit comments

Comments
 (0)