diff --git a/__tests__/fdir.test.ts b/__tests__/fdir.test.ts index 39481e6..f19efbf 100644 --- a/__tests__/fdir.test.ts +++ b/__tests__/fdir.test.ts @@ -327,6 +327,25 @@ for (const type of apiTypes) { mock.restore(); }); + test(`[${type}] crawl all files and include resolved symlinks without real paths with relative paths on`, async (t) => { + mock(mockFsWithSymlinks); + + const api = new fdir() + .withSymlinks({ resolvePaths: false }) + .withRelativePaths() + .withPathSeparator("/") + .crawl("/some/dir"); + const files = await api[type](); + t.expect(files).toHaveLength(3); + t.expect( + files.indexOf("dirSymlink/file-1") > -1 + ).toBeTruthy(); + t.expect( + files.indexOf("dirSymlink/file-excluded-1") > -1 + ).toBeTruthy(); + mock.restore(); + }); + test("crawl all files and include resolved symlinks with exclusions", async (t) => { mock(mockFsWithSymlinks); const api = new fdir() diff --git a/documentation.md b/documentation.md index 1a5ee84..e992a55 100644 --- a/documentation.md +++ b/documentation.md @@ -104,7 +104,7 @@ const crawler = new fdir().withDirs(); ### `withSymlinks({ resolvePaths: boolean })` -Use this to follow all symlinks recursively. +Use this to follow all symlinks recursively. Not available with relative paths on unless the parameter is set to `false`. **Parameters:** diff --git a/src/api/walker.ts b/src/api/walker.ts index be1f65e..c4a041d 100644 --- a/src/api/walker.ts +++ b/src/api/walker.ts @@ -117,14 +117,20 @@ export class Walker { if (exclude && exclude(entry.name, path)) continue; this.walkDirectory(this.state, path, depth - 1, this.walk); } else if (entry.isSymbolicLink() && resolveSymlinks) { - let path = this.joinPath(entry.name, directoryPath); + let path = directoryPath + entry.name; this.resolveSymlink!(path, this.state, (stat, resolvedPath) => { + resolvedPath = this.normalizePath(resolvedPath); + if (stat.isDirectory()) { - resolvedPath = this.normalizePath(resolvedPath); if (exclude && exclude(entry.name, resolvedPath)) return; - this.walkDirectory(this.state, resolvedPath, depth - 1, this.walk); } else { + if (!this.state.options.useRealPaths && this.state.options.relativePaths) { + resolvedPath = resolvedPath.substring(this.root.length, resolvedPath.length - 1); + } else { + // resolvedPath has a trailing slash due to the normalizePath call + resolvedPath = resolvedPath.substring(0, resolvedPath.length - 1) + } this.pushFile(resolvedPath, files, this.state.counts, filters); } });