From 07be7159ce93b9f24a1f62c3496398d1d35b96e1 Mon Sep 17 00:00:00 2001 From: Liam Murphy <43807659+Liamolucko@users.noreply.github.com> Date: Tue, 1 Dec 2020 01:34:36 +1100 Subject: [PATCH] feat(fs): Re-enable `followSymlinks` on `walk()` (denoland/deno#8479) --- fs/walk.ts | 17 ++++++++--------- fs/walk_test.ts | 5 ++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/walk.ts b/fs/walk.ts index 47e7e7afa832..4ce564435410 100644 --- a/fs/walk.ts +++ b/fs/walk.ts @@ -106,18 +106,17 @@ export async function* walk( return; } for await (const entry of Deno.readDir(root)) { + assert(entry.name != null); + let path = join(root, entry.name); + if (entry.isSymlink) { if (followSymlinks) { - // TODO(ry) Re-enable followSymlinks. - throw new Error("unimplemented"); + path = await Deno.realPath(path); } else { continue; } } - assert(entry.name != null); - const path = join(root, entry.name); - if (entry.isFile) { if (includeFiles && include(path, exts, match, skip)) { yield { path, ...entry }; @@ -159,17 +158,17 @@ export function* walkSync( return; } for (const entry of Deno.readDirSync(root)) { + assert(entry.name != null); + let path = join(root, entry.name); + if (entry.isSymlink) { if (followSymlinks) { - throw new Error("unimplemented"); + path = Deno.realPathSync(path); } else { continue; } } - assert(entry.name != null); - const path = join(root, entry.name); - if (entry.isFile) { if (includeFiles && include(path, exts, match, skip)) { yield { path, ...entry }; diff --git a/fs/walk_test.ts b/fs/walk_test.ts index c772f49121a8..eae21f7b1e43 100644 --- a/fs/walk_test.ts +++ b/fs/walk_test.ts @@ -252,12 +252,11 @@ testWalk( async function symlink(): Promise { assertReady(6); const files = await walkArray("a"); - assertEquals(files.length, 2); + assertEquals(files.length, 3); assert(!files.includes("a/bb/z")); const arr = await walkArray("a", { followSymlinks: true }); - assertEquals(arr.length, 3); + assertEquals(arr.length, 5); assert(arr.some((f): boolean => f.endsWith("/b/z"))); }, - true, );