Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not incorrectly use real paths on exclude predicate #129

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading