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

feat(std/fs): Re-enable "followSymlinks" option in "walk()" API #8479

Merged
merged 1 commit into from
Nov 30, 2020
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
17 changes: 8 additions & 9 deletions std/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 std/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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this one remain unchanged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think includeDirs was off by default back when this test was written, so now it includes "a" itself as well.

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,
);