Skip to content

Commit

Permalink
fix: add parentPath to Dirent (#1058)
Browse files Browse the repository at this point in the history
* #735 - add parentPath property to Dirent

* #735 - fix tests for parentPath property

* #735 - use Dirent parentPath instead of path in Volume
  • Loading branch information
SoulKa authored Sep 17, 2024
1 parent a6ec0bf commit 9156c84
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/Dirent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export class Dirent implements IDirent {
dirent.name = strToEncoding(link.getName(), encoding);
dirent.mode = mode;
dirent.path = link.getParentPath();
dirent.parentPath = dirent.path;

return dirent;
}

name: TDataOut = '';
path = '';
parentPath = '';
private mode: number = 0;

private _checkModeProperty(property: number): boolean {
Expand Down
26 changes: 13 additions & 13 deletions src/__tests__/volume/readdirSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ describe('readdirSync()', () => {
return { ...dirent };
});
expect(mapped).toEqual([
{ mode: 33206, name: 'af', path: '/x' },
{ mode: 16895, name: 'b', path: '/x' },
{ mode: 16895, name: 'c', path: '/x' },
{ mode: 33206, name: 'af', path: '/x', parentPath: '/x' },
{ mode: 16895, name: 'b', path: '/x', parentPath: '/x' },
{ mode: 16895, name: 'c', path: '/x', parentPath: '/x' },
]);
});

Expand Down Expand Up @@ -105,16 +105,16 @@ describe('readdirSync()', () => {
})
.sort((a, b) => a.path.localeCompare(b.path));
expect(mapped).toEqual([
{ mode: 33206, name: 'af1', path: '/z' },
{ mode: 33206, name: 'af2', path: '/z' },
{ mode: 16895, name: 'b', path: '/z' },
{ mode: 16895, name: 'c', path: '/z' },
{ mode: 33206, name: 'bf1', path: '/z/b' },
{ mode: 33206, name: 'bf2', path: '/z/b' },
{ mode: 16895, name: 'c', path: '/z/c' },
{ mode: 33206, name: '.cf0', path: '/z/c/c' },
{ mode: 33206, name: 'cf1', path: '/z/c/c' },
{ mode: 33206, name: 'cf2', path: '/z/c/c' },
{ mode: 33206, name: 'af1', path: '/z', parentPath: '/z' },
{ mode: 33206, name: 'af2', path: '/z', parentPath: '/z' },
{ mode: 16895, name: 'b', path: '/z', parentPath: '/z' },
{ mode: 16895, name: 'c', path: '/z', parentPath: '/z' },
{ mode: 33206, name: 'bf1', path: '/z/b', parentPath: '/z/b' },
{ mode: 33206, name: 'bf2', path: '/z/b', parentPath: '/z/b' },
{ mode: 16895, name: 'c', path: '/z/c', parentPath: '/z/c' },
{ mode: 33206, name: '.cf0', path: '/z/c/c', parentPath: '/z/c/c' },
{ mode: 33206, name: 'cf1', path: '/z/c/c', parentPath: '/z/c/c' },
{ mode: 33206, name: 'cf2', path: '/z/c/c', parentPath: '/z/c/c' },
]);
});
});
2 changes: 1 addition & 1 deletion src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ export class Volume implements FsCallbackApi, FsSynchronousApi {

return list.map(dirent => {
if (options.recursive) {
let fullPath = pathModule.join(dirent.path, dirent.name.toString());
let fullPath = pathModule.join(dirent.parentPath, dirent.name.toString());
if (isWin) {
fullPath = fullPath.replace(/\\/g, '/');
}
Expand Down

0 comments on commit 9156c84

Please sign in to comment.