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.rm cannot delete a symlink which is part of a loop #45404

Closed
nathanael-ruf opened this issue Nov 10, 2022 · 2 comments · Fixed by #45439
Closed

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

nathanael-ruf opened this issue Nov 10, 2022 · 2 comments · Fixed by #45439
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system.

Comments

@nathanael-ruf
Copy link
Contributor

nathanael-ruf commented Nov 10, 2022

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) => {

@nathanael-ruf
Copy link
Contributor Author

Workaround:

try {
    await rm(path, {...});
} catch (e) {
    if ('code' in e && e.code === 'ELOOP') {
         await unlink(p);
     }
}

@aduh95
Copy link
Contributor

aduh95 commented Nov 10, 2022

Thanks for the report. Would you be interested in sending a PR to fix this?

@aduh95 aduh95 added confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. labels Nov 10, 2022
nathanael-ruf added a commit to nathanael-ruf/node that referenced this issue Nov 12, 2022
nathanael-ruf added a commit to nathanael-ruf/node that referenced this issue Nov 12, 2022
Trott pushed a commit to nathanael-ruf/node that referenced this issue Nov 12, 2022
nathanael-ruf added a commit to nathanael-ruf/node that referenced this issue Nov 13, 2022
nodejs-github-bot pushed a commit that referenced this issue Nov 18, 2022
Fixes: #45404
PR-URL: #45439
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
ruyadorno pushed a commit that referenced this issue Nov 21, 2022
Fixes: #45404
PR-URL: #45439
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
marco-ippolito pushed a commit to marco-ippolito/node that referenced this issue Nov 23, 2022
Fixes: nodejs#45404
PR-URL: nodejs#45439
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 30, 2022
Fixes: #45404
PR-URL: #45439
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Dec 30, 2022
Fixes: #45404
PR-URL: #45439
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 3, 2023
Fixes: #45404
PR-URL: #45439
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
danielleadams pushed a commit that referenced this issue Jan 4, 2023
Fixes: #45404
PR-URL: #45439
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants