Skip to content

Commit

Permalink
feat(fs): Re-enable followSymlinks on walk() (denoland/deno#8479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liamolucko authored and caspervonb committed Jan 24, 2021
1 parent dbcda33 commit b8c8a4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
17 changes: 8 additions & 9 deletions fs/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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 };
Expand Down
5 changes: 2 additions & 3 deletions fs/walk_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,11 @@ testWalk(
async function symlink(): Promise<void> {
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,
);

0 comments on commit b8c8a4a

Please sign in to comment.