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

[v18.x] Wrong path returned by fs.readdir withFileTypes=true #52441

Open
H4ad opened this issue Apr 9, 2024 · 6 comments
Open

[v18.x] Wrong path returned by fs.readdir withFileTypes=true #52441

H4ad opened this issue Apr 9, 2024 · 6 comments
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system.

Comments

@H4ad
Copy link
Member

H4ad commented Apr 9, 2024

Version

18.20.1

Platform

Linux h4ad 6.5.0-27-generic #28~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 15 10:51:06 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

fs/promise

What steps will reproduce the bug?

You can reproduce the issue by running the following commands:

$ mkdir fs-issue
$ cd fs-issue
$ touch issue.txt
$ node -e "require('fs/promises').readdir('.', { withFileTypes: true, encoding: 'utf-8', }).then(console.log)" 

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

Always

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

The path should be ..

[
  Dirent {
    name: 'issue.txt',
    parentPath: '.',
    path: '.',
    [Symbol(type)]: 1
  }
]

What do you see instead?

The path is different:

[
  Dirent {
    name: 'issue.txt',
    parentPath: '.',
    path: 'issue.txt',
    [Symbol(type)]: 1
  }
]

This issue only happens on fs/promises, on readdirSync, we don't see this issue:

$ node --print "require('fs').readdirSync('.', { withFileTypes: true, encoding: 'utf-8', })"
[
  Dirent {
    name: 'issue.txt',
    parentPath: '.',
    path: '.',
    [Symbol(type)]: 1
  }
]

Also, if we include recursive, we don't see the issue:

$ node -e "require('fs/promises').readdir('.', { recursive:true, withFileTypes: true, encoding: 'utf-8', }).then(console.log)"
[
  Dirent {
    name: 'issue.txt',
    parentPath: '.',
    path: '.',
    [Symbol(type)]: 1
  }
]

Additional information

This bug was first introduced at 18.20.0, on 18.19.1 the behavior is correct.
On latest version of node, 21.7.2 and 20.12.1, we don't see this issue.

This bug was found by @wraithgar at npm/cli#7352 (comment)

@H4ad
Copy link
Member Author

H4ad commented Apr 9, 2024

The issue was probably introduced by this change introduced by #51021:

class DirentFromStats extends Dirent {
constructor(name, stats, path, filepath) {
super(name, null, path, filepath);
this[kStats] = stats;
}
}

The main PR #50976 didn't include these changes.

@H4ad H4ad added confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. labels Apr 10, 2024
@richardlau
Copy link
Member

cc @aduh95

@aduh95 aduh95 changed the title Wrong path returned by fs.readdir withFileTypes=true [v18.x] Wrong path returned by fs.readdir withFileTypes=true Apr 12, 2024
@ganialhamad
Copy link

hi guys, what's the status of this issue? I can look into it if it wasn't assigned to anyone yet

@H4ad
Copy link
Member Author

H4ad commented May 22, 2024

@gm-al Basically waiting for a PR, feel free to work on it if you want :) You can ping me when you had something to review

@jakecastelli
Copy link
Member

jakecastelli commented Jun 11, 2024

Just had a quick scan, looks like the current main does not have path property any more? was that intentional? (it was still there in v20.x, v22.x and I couldn't see it mentioned in the changelog or docs

@sonsurim
Copy link
Contributor

sonsurim commented Jul 16, 2024

Hello! May I try to resolve this issue?

sonsurim pushed a commit to sonsurim/node that referenced this issue Jul 21, 2024
…addir'

The issue was caused by a modification in PR nodejs#51021 , which was working on including the parentPath in the documentation and modifying the path to display the filepath.
I have retained the content related to the documentation and removed the filepath part.

Fixes: nodejs#52441

Co-authored-by: daeyoen <6630703+daeyeon@users.noreply.github.com>
Co-authored-by: injae-kim <injae-kim@users.noreply.github.com>"
sonsurim pushed a commit to sonsurim/node that referenced this issue Jul 21, 2024
The issue was caused by a modification in PR nodejs#51021, which included changes
to the documentation for parentPath and modifications to display the filepath.
I have retained the content related to the documentation and removed the
filepath part.

Fixes: nodejs#52441
Co-authored-by: injae-kim <injae-kim@users.noreply.github.com>
sonsurim pushed a commit to sonsurim/node that referenced this issue Jul 21, 2024
The issue was caused by a modification in PR nodejs#51021, which included changes
to the documentation for parentPath and modifications to display the filepath.
I have retained the content related to the documentation and removed the
filepath part.

Fixes: nodejs#52441
Co-authored-by: injae-kim <injae-kim@users.noreply.github.com>
sonsurim pushed a commit to sonsurim/node that referenced this issue Jul 21, 2024
The issue was caused by a modification in PR nodejs#51021,
which included changes to the documentation for parentPath
and modifications to display the file path.
I have retained the content related to the documentation
and removed the filepath part.

Fixes: nodejs#52441
Co-authored-by: injae-kim <injae-kim@users.noreply.github.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

No branches or pull requests

5 participants