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

fs.walk() has trouble with links #2313

Closed
joehillen opened this issue Jun 6, 2022 · 2 comments
Closed

fs.walk() has trouble with links #2313

joehillen opened this issue Jun 6, 2022 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@joehillen
Copy link
Contributor

Describe the bug

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
}

Environment

  • OS: BTW I use Arch
  • deno version: 1.22.2
  • std version: 0.142.0
@joehillen joehillen added bug Something isn't working needs triage labels Jun 6, 2022
@lucacasonato
Copy link
Member

I think this may be a duplicate of #1359. @joehillen can you take a look at that issue?

@joehillen
Copy link
Contributor Author

Yup. It's a dup. I'll repost my message there for more context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants