Skip to content

fs.rm cannot delete a symlink which is part of a loop #45404

Closed
@nathanael-ruf

Description

@nathanael-ruf

Version

18.12.1

Platform

Darwin Nathanaels-MBP.fritz.box 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103 arm64

Subsystem

fs

What steps will reproduce the bug?

mkdir repro
cd repro
ln -s a b && ln -s b a
node -e 'fs.rmSync("a")'
cd ..
rm -r repro

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

Always. No.

What is the expected behavior?

Can delete symlinks that form a loop.

What do you see instead?

This error

Uncaught Error: ELOOP: too many symbolic links encountered, stat 'a'
    at Object.statSync (node:fs:1596:3)
    at __node_internal_ (node:internal/fs/utils:804:8)
    at Object.rmSync (node:fs:1272:13) {
  errno: -62,
  syscall: 'stat',
  code: 'ELOOP',
  path: 'a'
}

Additional information

This stat call should probably be a lstatcall.

lazyLoadFs().stat(path, (err, stats) => {

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.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