FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[v18.x backport] fs: fix the file name is not included when the withFileTypes option of readdir by sonsurim · Pull Request #53969 · nodejs/node · GitHub

/ node Public

[v18.x backport] fs: fix the file name is not included when the withFileTypes option of readdir - #53969

Closed
sonsurim wants to merge 3 commits into
nodejs:v18.x-stagingfrom
sonsurim:fix-readdir-withFileType
Closed

[v18.x backport] fs: fix the file name is not included when the withFileTypes option of readdir#53969
sonsurim wants to merge 3 commits into
nodejs:v18.x-stagingfrom
sonsurim:fix-readdir-withFileType

Conversation

sonsurim commented Jul 20, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

This fixes the issue reported in #52441

The issue was caused by a modification in PR #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. Corresponding test code has also been updated accordingly.

An error occurred in the test/sequential/test-fs-opendir-recursive.js file after changing the code. This was resolved by referring to the code resolved in #49603 .

cc. @H4ad @daeyeon

Screenshots

AS-IS
You can see that even the file name is exposed in the path.

{
  const dir = await readdir(tmpDir, { withFileTypes: true });
  console.log(dir);
}

TO-BE
Now the file name has been removed from the path!

{
  const dir = await readdir(tmpDir, { withFileTypes: true });
  console.log(dir);
}

References

nodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. v18.x labels Jul 20, 2024
sonsurim force-pushed the fix-readdir-withFileType branch 2 times, most recently from 3ef999e to 7e1b5de Compare July 21, 2024 02:49

daeyeon commented Jul 21, 2024

Copy link
Copy Markdown
Member

Congrats on your first contribution! 🎉
Please update the commit message per the guide to fix the CI issue. Also, remove me as a co-author since I didn't directly contribute and don't qualify. :-)

sonsurim force-pushed the fix-readdir-withFileType branch 2 times, most recently from 9d97bac to d740bdb Compare July 21, 2024 07:23

Copy link
Copy Markdown
Contributor Author

The git config was not set up properly, so I committed it again. 😅

aduh95 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This one is simply very hard to fix without introducing more breaking changes. It might be more wise to consider dirent.path irremediably broken and switch to using dirent.parentPath which is stable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This change is not OK, we cannot make this kind of breaking change, especially on a maintenance LTS line. This needs to remain as it was on v18.19.1:

return pathModule.relative(testDir, dirent.path);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I got it! I fixed in b2d61d8.
Many Thanks!

Copy link
Copy Markdown
Contributor Author

@aduh95 Thanks for the review!

It might be more wise to consider dirent.path irremediably broken and switch to using dirent.parentPath which is stable.

Does the above mean modifying the readSyncRecursive function to use parentPath instead of path?

// dir.js
readSyncRecursive(dirent) {
    const ctx = { path: dirent.parentPath };
    const handle = dirBinding.opendir(
      pathModule.toNamespacedPath(dirent.parentPath),
      this[kDirOptions].encoding,
      undefined,
      ctx,
    );
    handleErrorFromBinding(ctx);
    const result = handle.read(
      this[kDirOptions].encoding,
      this[kDirOptions].bufferSize,
      undefined,
      ctx,
    );

    if (result) {
      this.processReadResult(dirent.parentPath, result);
    }

    handle.close(undefined, ctx);
    handleErrorFromBinding(ctx);
  }

Could you please help me a little more?

aduh95 commented Jul 21, 2024

Copy link
Copy Markdown
Contributor

Does the above mean modifying the readSyncRecursive function to use parentPath instead of path?

No I meant for user land, Im unsure fixing it in Node.js is worth it

sonny and others added 3 commits July 21, 2024 21:17
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>
An error occurred in the test/sequential/test-fs-opendir-recursive.js file
after changing the code. This was resolved by referring to the code resolved
in PR nodejs#49603.

Refs: nodejs#49603
The getDirentPath function in test/sequential/test-fs-opendir-recursive.js has been reverted for stability.

Refs: nodejs#53969 (comment)
sonsurim force-pushed the fix-readdir-withFileType branch from b2d61d8 to 4d34bb6 Compare July 21, 2024 12:20

H4ad commented Jul 21, 2024

Copy link
Copy Markdown
Member

This one is simply very hard to fix without introducing more breaking changes. It might be more wise to consider dirent.path irremediably broken and switch to using dirent.parentPath which is stable.

Doesn't make sense this statement since on the sync version we have the correct behavior, unless you want to change the sync version.

aduh95 commented Jul 21, 2024

Copy link
Copy Markdown
Contributor

unless you want to change the sync version.

No that would be equally unwise IMO. What I'm saying is that dirent.path is inconsistent, and I don't see a way to fix the inconsistency without risking breaking more stuff. dirent.parentPath was introduced because dirent.path is inconsistent and unfortunately the ecosystem was/is relying on some of these inconsistencies.
If there's a way to bring back the behavior of v18.19.1 without breaking dirent.parentPath, I think we should consider doing so; I couldn't figure a way for doing so, I'm not saying it's impossible, but given the fact that v18.19.1 behavior is also inconsistent, I'm not sure it's worth doing.

Copy link
Copy Markdown
Contributor Author

I will wait for the direction of the work to be decided. If you decide, please let me know!

sonsurim closed this Aug 19, 2024
sonsurim deleted the fix-readdir-withFileType branch August 19, 2024 12:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

5 participants


Back | FazBrowse Home | New Git URL