Skip to content

fs.readdirSync(recursive=true) should not follow follow symlinks by default #51858

Open
@myocytebd

Description

@myocytebd

Version

v21.6.2

Platform

Linux 6.5.0-15-generic #15~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC x86_64 x86_64 x86_64 GNU/Linux

Subsystem

fs

What steps will reproduce the bug?

  • Ensure a directory tree with symlink, e.g.
./
../
mylink -> ../other_dir/
  • fs.readdirSync('.', { recursive: true })

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

[ './mylink' ]

What do you see instead?

All files under ../other_dir/ are listed.

Additional information

This behavior is extremely surprising and error-prone, since common commands like find or Get-ChildItem does not follow symlink by default.
In addition, it is not documented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions