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

lib: avoid excluding symlinks in recursive fs.readdir with filetypes #55714

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

juanarbol
Copy link
Member

Fixes: #52663

@nodejs-github-bot nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Nov 4, 2024
@juanarbol juanarbol added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 4, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 4, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.42%. Comparing base (6af5c4e) to head (a8a6aa0).
Report is 55 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55714      +/-   ##
==========================================
+ Coverage   88.41%   88.42%   +0.01%     
==========================================
  Files         654      654              
  Lines      187757   187863     +106     
  Branches    36129    36148      +19     
==========================================
+ Hits       166003   166119     +116     
+ Misses      14997    14982      -15     
- Partials     6757     6762       +5     
Files with missing lines Coverage Δ
lib/fs.js 98.26% <100.00%> (+0.11%) ⬆️

... and 54 files with indirect coverage changes

@Ethan-Arrowood
Copy link
Contributor

Please add a test; otherwise lgtm

@Ethan-Arrowood Ethan-Arrowood self-assigned this Nov 6, 2024
@juanarbol
Copy link
Member Author

Please add a test; otherwise lgtm

Will do

@juanarbol juanarbol force-pushed the juan/fs-readdir branch 2 times, most recently from 0330a1d to 10a71b9 Compare November 14, 2024 01:36
@juanarbol
Copy link
Member Author

@Ethan-Arrowood there we go!

Comment on lines 29 to 30
fs.readdirSync(a, { withFileTypes: true }).length,
fs.readdirSync(a, { withFileTypes: false }).length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you not missing the recursive: true option here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The directory you are creating here would look like:

|- a/
|   |- file
|   | b -> a/

And so I would expect readdirSync('a') to return only 2 items, 'file' and 'b'.

When recursive: true is enabled, what should happen? Would it be infinite?

That infinite behavior is potentially a separate issue.

Can you simplify the link here to maybe do something like:

|- x/
|   |- 1
|   |- 2
|- a/
|   |- 1
|   | b -> x/

And then assert that readdir('a', { recursive: true }) results in 4 entries?

'a/1', 'a/b', 'a/b/1', 'a/b/2'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subsequently, it would be great to verify that such a test case currently fails on main, but passes with your changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this is main

./node --inspect test/parallel/test-fs-readdir-types-symlinks.js
Debugger listening on ws://127.0.0.1:9229/8079dfce-ab06-46ca-b559-6dc4268378a4
For help, see: https://nodejs.org/en/docs/inspector
[
  Dirent {
    name: '1',
    parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
    [Symbol(type)]: 1
  },
  Dirent {
    name: 'c',
    parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
    [Symbol(type)]: 3
  }
]
[ '1', 'c', 'c/1', 'c/2' ]
node:assert:90
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

2 !== 4

And this is w/ this patch

./node --inspect test/parallel/test-fs-readdir-types-symlinks.js
Debugger listening on ws://127.0.0.1:9229/a2e2b4d3-6427-4488-858d-0cda545665ff
For help, see: https://nodejs.org/en/docs/inspector
[
  Dirent {
    name: '1',
    parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
    [Symbol(type)]: 1
  },
  Dirent {
    name: 'c',
    parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
    [Symbol(type)]: 3
  },
  Dirent {
    name: '1',
    parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b/c',
    [Symbol(type)]: 1
  },
  Dirent {
    name: '2',
    parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b/c',
    [Symbol(type)]: 1
  }
]
[ '1', 'c', 'c/1', 'c/2' ]

@juanarbol
Copy link
Member Author

@Ethan-Arrowood you were right, I've addressed your suggestions and tested the thing w/ main branch build.

@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

withFileTypes has different behavior in fs.readdir when reading symbolic directories
3 participants