Skip to content

Commit

Permalink
fix: do not incorrectly use real paths on exclude predicate (#129)
Browse files Browse the repository at this point in the history
* fix: do not incorrectly use real paths on exclude predicate

* chore: add new test

* chore: fix test name
  • Loading branch information
SuperchupuDev authored Dec 23, 2024
1 parent ffb2762 commit 5d1e534
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions __tests__/symlinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ for (const type of apiTypes) {
t.expect(files.sort()).toStrictEqual(normalize(["/other/dir/file-2"]));
});

test("resolve symlinks (exclude /some/dir/dirSymlink/, real paths: false)", async (t) => {
const api = new fdir()
.withSymlinks({ resolvePaths: false })
.exclude((_name, path) => path === resolveSymlinkRoot("/some/dir/dirSymlink/"))
.crawl("/some/dir")
const files = await api[type]();
t.expect(files.sort()).toStrictEqual(normalize(["/some/dir/fileSymlink"]));
});

test(`do not resolve symlinks`, async (t) => {
const api = new fdir().crawl("/some/dir");
const files = await api[type]();
Expand Down
2 changes: 1 addition & 1 deletion src/api/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class Walker<TOutput extends Output> {
this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
if (stat.isDirectory()) {
resolvedPath = normalizePath(resolvedPath, this.state.options);
if (exclude && exclude(entry.name, resolvedPath)) return;
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;

this.walkDirectory(
this.state,
Expand Down

0 comments on commit 5d1e534

Please sign in to comment.