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

walk and walkSync skip over symlinks when followSymlinks: false #1359

Closed
lucacasonato opened this issue Oct 6, 2021 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@lucacasonato
Copy link
Member

Instead I would expect symlinks to be yielded just like files: if includeSymlinks is set & the symlink matches the exts, match, and skip options.

@lucacasonato lucacasonato added bug Something isn't working needs triage labels Oct 6, 2021
@iwinux
Copy link

iwinux commented May 9, 2022

Forget the deleted comment, my mistake.

The "if not follow symlink then continue (skip)" logic actually dates back to the initial fs.walk implementation (see #192), and gets carried over since then.

Would someone who knows the background explain the decision behind this? It seems like an easy fix (just remove the continue branch) but I'm afraid that something might break if we change that.

@joehillen
Copy link
Contributor

Here is some more context from the duplicate issue I posed:

This is really 2 issues:

  1. no symbolic link files are returned when using walk(). See below to reproduce.

  2. when using followSymlinks: true, the path to the destination is returned and labeled { isFile: false, isSymlink: true }, even though the destination is a regular file.

Steps to Reproduce

// walkTest.ts

import * as fs from "https://deno.land/std@0.142.0/fs/mod.ts";

fs.emptyDirSync("dir");

fs.ensureFileSync("dir/files/a.txt");
Deno.writeTextFileSync("dir/files/a.txt", "A");

// FIXME: See https://github.com/denoland/deno_std/issues/2312
// fs.ensureSymlinkSync("../files/a.txt", "dir/links/a.txt");

fs.ensureDirSync("dir/links");
await Deno.run({
  cmd: ["ln", "-s", "../files/a.txt", "dir/links/a.txt"],
}).status();

/*
  dir
  ├── files
  │   └── a.txt
  └── links
      └── a.txt -> ../files/a.txt
*/

console.log(">>> followSymlinks: false >>>>");
for (const f of fs.walkSync("dir", { followSymlinks: false })) {
  console.log(f); // dir/links/a.txt is not returned
}

console.log(">>> followSymlinks: true >>>>");
for (const f of fs.walkSync("dir", { followSymlinks: true })) {
  console.log(f);
  // returns:
  //  {
  //    path: "/home/joe/tmp/walkTest/dir/files/a.txt", <-- this is the path to the destination, not the link file.
  //    name: "a.txt",
  //    isFile: false,
  //    isDirectory: false,
  //    isSymlink: true <-- "path" is a file, not a symlink
  //  }
}

Expected behavior

fs.walkSync("dir", { followSymlinks: false } should include:

{
  path: "dir/links/a.txt",
  name: "a.txt",
  isFile: true,
  isDirectory: false,
  isSymlink: true
}

fs.walkSync("dir", { followSymlinks: true }) should return:

{
  path: "/home/joe/tmp/walkTest/dir/files/a.txt",
  name: "a.txt",
  isFile: true,
  isDirectory: false,
  isSymlink: false
}

joehillen added a commit to joehillen/deno_std that referenced this issue Jun 17, 2023
Symbolic links were not returned. This means that `walk()` is not listing
all the contents of a directory.

Some use cases for this is are:

- Copying a directory recursively.
- Finding invalid symbolic links.
- Modify link targets without resolving them.

Other changes:

- walk_test.ts: Rename `walkArray()` to `collectPaths()`
  because it is more descriptive.
- walk_test.ts: Add `collectEntries()`
joehillen added a commit to joehillen/deno_std that referenced this issue Jul 18, 2023
Symbolic links were not returned. This means that `walk()` is not listing
all the contents of a directory.

Some use cases for this is are:

- Copying a directory recursively.
- Finding invalid symbolic links.
- Modify link targets without resolving them.

Other changes:

- walk_test.ts: Rename `walkArray()` to `collectPaths()`
  because it is more descriptive.
- walk_test.ts: Add `collectEntries()`
joehillen added a commit to joehillen/deno_std that referenced this issue Jul 18, 2023
Symbolic links were not returned. This means that `walk()` is not listing
all the contents of a directory.

Some use cases for this is are:

- Copying a directory recursively.
- Finding invalid symbolic links.
- Modify link targets without resolving them.

Other changes:

- walk_test.ts: Rename `walkArray()` to `collectPaths()`
  because it is more descriptive.
- walk_test.ts: Add `collectEntries()`
joehillen added a commit to joehillen/deno_std that referenced this issue Jul 19, 2023
Symbolic links were not returned. This means that `walk()` is not listing
all the contents of a directory.

Some use cases for this is are:

- Copying a directory recursively.
- Finding invalid symbolic links.
- Modify link targets without resolving them.

Other changes:

- walk_test.ts: Rename `walkArray()` to `collectPaths()`
  because it is more descriptive.
- walk_test.ts: Add `collectEntries()`
@kt3k
Copy link
Member

kt3k commented Jul 27, 2023

fixed in #3464

Now includeSymlinks defaults to true. Is there any concern on this default?

@kt3k kt3k closed this as completed Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants