Skip to content
Merged
8 changes: 6 additions & 2 deletions __tests__/symlinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,13 @@ for (const type of apiTypes) {

test(
"doesn't hang when resolving symlinks in the root directory",
async () => {
async (t) => {
const api = new fdir().withSymlinks({ resolvePaths: false }).crawl("/");
await api[type]();
const files = await api[type]();
const expectedFiles = normalize(["/lib/file-1", "/usr/lib/file-1"])
for (const expectedFile of expectedFiles) {
t.expect(files).toContain(expectedFile);
}
},
{ timeout: 1000 }
);
Expand Down
4 changes: 2 additions & 2 deletions src/api/walker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { basename, dirname } from "path";
import { normalizePath } from "../utils";
import { isRootDirectory, normalizePath } from "../utils";
import { ResultCallback, WalkerState, Options } from "../types";
import * as joinPath from "./functions/join-path";
import * as pushDirectory from "./functions/push-directory";
Expand Down Expand Up @@ -37,7 +37,7 @@ export class Walker<TOutput extends Output> {

this.root = normalizePath(root, options);
this.state = {
root: this.root === "/" ? this.root : this.root.slice(0, -1),
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
// Perf: we explicitly tell the compiler to optimize for String arrays
paths: [""].slice(0, 0),
groups: [],
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function convertSlashes(path: string, separator: PathSeparator) {
return path.replace(SLASHES_REGEX, separator);
}

export function isRootDirectory(path: string) {
return path === "/" || /^[a-z]:\\$/i.test(path);
}

export function normalizePath(
path: string,
options: {
Expand Down
Loading