GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: restore javascript realpath implementation by bzoz · Pull Request #7899 · nodejs/node

Conversation

@bzoz

@bzoz bzoz commented Jul 27, 2016

Copy link
Copy Markdown
Contributor
Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

fs

Description of change

Libuv realpath implementation brought a lot of problems described here #7726. This restores old JS implementation of realpath and realpathSync, adding new API, with options in place of cache.

This requires #7846 to land, as it reverts changes to fs on which old JS implementation depended. This PR is about 3rd and 4th commit which bring back old realpath implementation with support for the new API.

First two commits are from #7846, reverting some changes to fs that landed after JS realpath implementation was dropped.

Third commit reverts b488b19 bringing back JS implementation of realpath and realpathSync.

Fourth commit updates old implementation. It removes the cache and implements new realpath API (support for encoding parameter).

This cannot land before #7846. In case #7846 does not make it, this can be easily updated.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module. labels Jul 27, 2016
@addaleax

addaleax commented Jul 27, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

A couple of suggestions:

  • I don’t think the native binding to the libuv realpath needs to be removed. It can be, but it might be nice to retain it for comparing results with the JS implementation later.
  • You could add the benchmark/test commit from @trevnorris’ fs: fix long symlinks in realpath #7548 here.
  • I’ll try to benchmark it, but removing the cache altogether sounds like something that won’t work out. I realize that it conflicts with the encoding: option, but that seems to be easily worked around by never adding an encoding: key to the cache? It also won’t be a likely problem in practice, because only path.resolve()d keys are added to the cache. People in the CTC meeting made some good points and removing the cache sounds okay.
  • The encoding option should probably be used for all fs.* calls that are made from inside the realpath implementations?
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orangemocha orangemocha mentioned this pull request Jul 27, 2016
[meta] realpath issues in v6 #7726
Closed
7 tasks
@orangemocha

orangemocha commented Jul 27, 2016

Copy link
Copy Markdown
Contributor

CI run: https://ci.nodejs.org/job/node-test-pull-request/3441/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@orangemocha

orangemocha commented Jul 27, 2016

Copy link
Copy Markdown
Contributor

At the last meeting, the CTC has expressed consensus with the approach in this PR: reverting, leaving the cache out, but keeping the encoding option.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChALkeR

ChALkeR commented Jul 27, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

To me it looks like this reverts too many tests. Could we keep the ones that still pass?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz

bzoz commented Jul 28, 2016

Copy link
Copy Markdown
Contributor Author

@addaleax :

  • I think that since we are not using native realpath anymore there is no need to keep bindings around.
  • Adding benchmarks from fs: fix long symlinks in realpath #7548 is a good idea, I'll do that.
  • Inside we are using path.resolve, which expects utf-8 strings. So we stick to them when calling other fs functions, and only apply encoding option when returning result.

@ChALkeR: Those test are reverted by #7846 on which this PR depends.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Jul 28, 2016

Copy link
Copy Markdown
Member

I think that since we are not using native realpath anymore there is no need to keep bindings around.

@bzoz Your call.There seems to be agreement that the long-term plan is to use a fixed libuv implementation, though, and I think keeping the binding around might be useful for e.g. comparative benchmarks.

we are using path.resolve, which expects utf-8 strings

path.resolve expects strings, which means that it it isn’t concerned with encodings at all. But you’re right, this is not as easy as I though it would be, and it’s probably best to just stick with UTF-8 for all intermediate results (and accepting that that means that symlinks encountered along the way must be valid UTF-8).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz
bzoz force-pushed the bartek-restore-js-realpath branch from bddaab2 to 0329b6a Compare July 28, 2016 16:27
@jasnell

jasnell commented Jul 28, 2016

Copy link
Copy Markdown
Member

In general this LGTM with a green CI. I definitely want to make sure this gets additional eyes on it to review, however. @nodejs/ctc

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StefanScherer

StefanScherer commented Jul 28, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

@bzoz I've just compiled your PR on Windows and tried the node.exe inside a Windows Container. Installed Node.js 6.3.1 from MSI inside the container and just replaced node.exe.

Running npm init, npm install express ... works fine again. 🐳
So this PR would fix #7044

addaleax reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saghul

saghul commented Jul 29, 2016

Copy link
Copy Markdown
Member

Why does this PR also revert "fs: validate args of truncate functions in js" and "fs: make callback mandatory to all async functions" ? How are those related to the realpath problems? It makes is a lot harder to review this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saghul

saghul commented Jul 29, 2016

Copy link
Copy Markdown
Member

Those seem to be handled by #7846, btw.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Jul 29, 2016

Copy link
Copy Markdown
Member

@saghul This PR would otherwise create merge conflicts, that’s all; the intent here is to wait until #7846 is landed, if I understood @bzoz correctly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax
addaleax reviewed Jul 29, 2016
View reviewed changes
Comment thread test/parallel/test-fs-realpath-on-substed-drive.js Outdated

@addaleax addaleax Jul 29, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You don’t need the asyncCompleted checks; wrapping the callback as common.mustCall(function(err, result) { … }) handles that automatically for you.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@addaleax

addaleax commented Jul 29, 2016

Copy link
Copy Markdown
Member

@bzoz Many, many thanks for starting to add regression tests! Overall LGTM, too.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz

bzoz commented Jul 29, 2016

Copy link
Copy Markdown
Contributor Author

CI run: https://ci.nodejs.org/job/node-test-pull-request/3453/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax mentioned this pull request Aug 2, 2016
Revert fs changes #7846
Closed
2 tasks done
@addaleax

addaleax commented Aug 2, 2016

Copy link
Copy Markdown
Member

LGTM, thanks for doing the work behind this PR!

CI: https://ci.nodejs.org/job/node-test-commit/4374/

bzoz reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Aug 2, 2016

Copy link
Copy Markdown
Member

One Windows build bot failure, running CI again to be safe: https://ci.nodejs.org/job/node-test-commit/4376/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz

bzoz commented Aug 2, 2016

Copy link
Copy Markdown
Contributor Author

I had one running here https://ci.nodejs.org/job/node-test-commit/4373/, it is green.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Aug 2, 2016

Copy link
Copy Markdown
Member

Oh, sorry (but good to hear)! I’d say this is good to go once #7846 is resolved.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@misterdjules

misterdjules commented Aug 2, 2016

Copy link
Copy Markdown

@bzoz What do you think of squashing all commits but the ones from #7846 to make reviewing changes easier? Currently one has to go through all these commits separately in order to focus on reviewing the changes that are actually related to this PR, which is a bit tedious.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz
bzoz force-pushed the bartek-restore-js-realpath branch from 28efdae to 0c0a6b4 Compare August 3, 2016 09:08
@bzoz

bzoz commented Aug 3, 2016

Copy link
Copy Markdown
Contributor Author

@misterdjules OK, squashed

Commits:

  1. Restore old js realpath implementation
  2. Implement new API (i.e. options.encoding) and add a test
  3. Add tests and benchmarks from fs: fix long symlinks in realpath #7548
  4. Remove one test from fs: fix long symlinks in realpath #7548 which was failing
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saghul

saghul commented Aug 3, 2016

Copy link
Copy Markdown
Member

What was the result of the discussion about the substed realpath behavior thing? This PR adds a test thus making certain behavior "correct" which might not necessarily be the case. It depends on how substed drives are interpreted, IMHO.

On the maze of issues and notes I recall reading that some people where using substed drives to get shorter paths. Was that the case? What breaks if we would give them the long path?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz

bzoz commented Aug 10, 2016

Copy link
Copy Markdown
Contributor Author

I've added a note to the fs documentation.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Aug 10, 2016

Copy link
Copy Markdown
Member

LGTM, thank you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented Aug 10, 2016

Copy link
Copy Markdown
Member

CI is green. Let's give it another day before landing. @nodejs/ctc @nodejs/collaborators ... please take one final look.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

saghul
saghul reviewed Aug 10, 2016
View reviewed changes
Comment thread lib/fs.js Outdated


fs.realpathSync = function realpathSync(path, options) {
// Regexp that finds the next partion of a (partial) path

@saghul saghul Aug 10, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

typo: partion

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bzoz bzoz Aug 11, 2016

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

fixed

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bzoz
fixup: spelling
1ed6028
bzoz added a commit that referenced this pull request Aug 12, 2016
@bzoz
fs: restore JS implementation of realpath
08996fd
This reverts parts of b488b19
restoring javascript implementation of realpath and realpathSync.

Fixes: #7175
Fixes: #6861
Fixes: #7294
Fixes: #7192
Fixes: #7044
Fixes: #6624
Fixes: #6978
PR-URL: #7899
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
bzoz pushed a commit that referenced this pull request Aug 12, 2016
@trevnorris @bzoz
bench: add bench for fs.realpath() fix
b9832eb
The benchmarks included also work for the previous JS
implementation of fs.realpath(). In case the new implementation of
realpath() needs to be reverted, we want these changes to stick around.

PR-URL: #7899
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@bzoz

bzoz commented Aug 12, 2016

Copy link
Copy Markdown
Contributor Author

Landed in 08996fd and b9832eb

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz bzoz closed this Aug 12, 2016
cjihrig pushed a commit that referenced this pull request Aug 15, 2016
@bzoz @cjihrig
fs: restore JS implementation of realpath
18a3064
This reverts parts of b488b19
restoring javascript implementation of realpath and realpathSync.

Fixes: #7175
Fixes: #6861
Fixes: #7294
Fixes: #7192
Fixes: #7044
Fixes: #6624
Fixes: #6978
PR-URL: #7899
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
cjihrig pushed a commit that referenced this pull request Aug 15, 2016
@trevnorris @cjihrig
bench: add bench for fs.realpath() fix
f6713bf
The benchmarks included also work for the previous JS
implementation of fs.realpath(). In case the new implementation of
realpath() needs to be reverted, we want these changes to stick around.

PR-URL: #7899
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
@cjihrig cjihrig mentioned this pull request Aug 15, 2016
v6.4.0 Proposal #8070
Merged
@vadimi vadimi mentioned this pull request Aug 16, 2016
Case sensitive comparison issue on Windows, node 6.3 WearyMonkey/ngtemplate-loader#49
Closed
@vsemozhetbyt vsemozhetbyt mentioned this pull request Aug 20, 2016
(reading files issue) ENOENT: no such file or dicrectory - fs:js.640 electron/electron#6911
Closed
@MylesBorins MylesBorins added the dont-land-on-v4.x label Sep 9, 2016
@bpasero

bpasero commented Sep 22, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

@bzoz @addaleax one thing I really liked from the behaviour of native fs.realpath is that it would return the actual casing of a path as it exists on disk. E.g. if there is an actual path /foo/bar/some.txt, running fs.realpath("/foo/BAR/some.txt") would return /foo/bar/some.txt. Are there any plans to support this behaviour after going back to the old JS implementation? Or any plans to provide this functionality in a separate method?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented Sep 22, 2016

Copy link
Copy Markdown
Member

@bpasero I guess you can open a separate issue for this? It sounds like something that would be okay to have.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bpasero bpasero mentioned this pull request Sep 22, 2016
Provide a way to call the native realpath function #8715
Closed
@bpasero

bpasero commented Sep 22, 2016

Copy link
Copy Markdown
Contributor

@addaleax makes sense, opened #8715

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@damieng damieng mentioned this pull request Nov 15, 2016
Network mapped paths resolve differently in Atom 1.12 atom/atom#13104
Closed
6 tasks done
@bnoordhuis bnoordhuis mentioned this pull request Oct 5, 2017
fs: expose realpath(3) bindings #15776
Merged
bnoordhuis added a commit to bnoordhuis/io.js that referenced this pull request Nov 9, 2017
@bnoordhuis
fs: expose realpath(3) bindings
74023c0
Make the `uv_fs_realpath()` binding (which calls the libc `realpath()`
on UNIX and `GetFinalPathNameByHandle()` on Windows) available as the
`fs.realpath.native()` and `fs.realpathSync.native()` functions.

The binding was already available as `process.binding('fs').realpath`
but was not exposed or tested - and partly broken as a result.

Fixes: nodejs#8715
PR-URL: nodejs#15776
Refs: nodejs#7899
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
evanlucas pushed a commit that referenced this pull request Nov 13, 2017
@bnoordhuis @evanlucas
fs: expose realpath(3) bindings
8611e3b
Make the `uv_fs_realpath()` binding (which calls the libc `realpath()`
on UNIX and `GetFinalPathNameByHandle()` on Windows) available as the
`fs.realpath.native()` and `fs.realpathSync.native()` functions.

The binding was already available as `process.binding('fs').realpath`
but was not exposed or tested - and partly broken as a result.

Fixes: #8715
PR-URL: #15776
Refs: #7899
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
@bjcairns bjcairns mentioned this pull request Aug 5, 2019
realize_ does not work if the path points toward a network drive r-lib/fs#147
Open
@bluwy bluwy mentioned this pull request Nov 16, 2022
fix: reduce number of fs.realpath calls vitejs/vite#6412
Closed
1 of 9 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jun 30, 2026
🛡️ Sentinel: [security improvement] Fix path traversal vulnerabilities gadgetmies/cascade-test#141
Open
@jonathanlindsay jonathanlindsay mentioned this pull request Sep 28, 2026
Windows AppContainer: realpath fails (native lookup refused with error 5; JS walk refused at lstat 'C:\Users') #66375
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to file-system APIs and the fs module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

12 participants

@bzoz @addaleax @orangemocha @ChALkeR @jasnell @StefanScherer @saghul @misterdjules @bpasero @MylesBorins @nodejs-github-bot @trevnorris
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.