-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: fix realpath{Sync} on resolving pipes/sockets #13028
Conversation
4104b3d
to
84cbd7a
Compare
'use strict'; | ||
|
||
// Skip Windows as /dev/stdin is not available | ||
if (process.platform === 'win32') |
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.
Use common.isWindows
and common.skip()
here instead. See here for an example.
});`, | ||
`console.log(require('fs').realpathSync('/dev/stdin'));` | ||
]) { | ||
const child = spawn(process.execPath, ['-e', code], { stdio: 'pipe' }); |
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.
Consider using spawnSync()
instead to simplify this a bit and to make future debugging a bit easier.
84cbd7a
to
1fa2c30
Compare
Both done. |
1fa2c30
to
dbac492
Compare
This probably needs more study, both of just not following (this patch) and following to the end and raising [current] or not raising error on following symlinks to pipes/sockets should be discussed, lets close it for now. |
dbac492
to
00f1de7
Compare
Updated to follow python result. |
c630b2b
to
f39045a
Compare
@refack: Hi. Thanks for reviewing my patches. :) Does this need a documentation change also? |
Have a look at #13130 (comment) also |
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.
Need documentation.
process.exit(1); | ||
};` | ||
]) { | ||
assert.strictEqual(spawnSync(process.execPath, ['-e', code], { |
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.
In adition to sanity, I would consider asserting the value of resolvedPath
and the returned value from require('fs').realpathSync('/dev/stdin');
Either in the script literal or console.log
ing it and adding another assert for stdout.
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.
Hmm, that resolves to different things on different runs and platforms, that is hard to check I think
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.
Than check it has a truthy value if (!resolvedPath) process.exit(2)
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.
Done
@ebraminio Yes, I would add a note to fs.md#fsrealpathpath-options-callback and Something like *Note*: If `path` resolves to a Socket or a Pipe, the function will return the value of `require('path').resolve(path)`. P.S. this might be a breaking change (a.k.a |
Or is it converted by the notes? |
e65f679
to
035b935
Compare
doc is done now, have a look |
doc/api/fs.md
Outdated
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/13028 | ||
description: Pipe/Socket resolve support was added. | ||
- version: REPLACEME |
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.
Rebase on master
this comment was reverted.
035b935
to
f0146f4
Compare
doc/api/fs.md
Outdated
@@ -1872,10 +1879,16 @@ object with an `encoding` property specifying the character encoding to use for | |||
the path passed to the callback. If the `encoding` is set to `'buffer'`, | |||
the path returned will be passed as a `Buffer` object. | |||
|
|||
*Note*: If `path` resolves to a Socket or a Pipe, the function will return the |
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.
BTW is my note actually correct? In that case it's easy to check in the test.
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.
No I've copy-pasted your comment just in rush, removed the both as I couldn't reach to anything useful for here.
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.
Show me some input -> output results. I'll phrase something better.
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.
I am not sure what it should be called, before my patch echo "" | node -e "require('fs').realpath('/dev/stdin', console.log)"
was raising error but with my patch now it has a similar result with python, say /proc/12938/fd/pipe:[224961]
, just on Linux
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.
*Note*: If `path` resolves to a socket or a pipe, the function will return a system dependent name for that object.
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.
Done
e8ed5ba
to
eef07fc
Compare
So there are a linting error:
and a fail on AIX: assert.js:92
throw new AssertionError({
^
AssertionError [ERR_ASSERTION]: 1 === 2
at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-aix/nodes/aix61-ppc64/test/parallel/test-fs-realpath-pipe.js:33:10) If you don't have a clear idea why this fails on AIX, and since this is not a regression, we could add it to |
e1ae7c5
to
9746ad1
Compare
Done. I don't have access to AIX but perhaps it doesn't have the concept of /dev/stdin or that somehow is different there. |
cc @nodejs/platform-aix |
AIX does not have /dev/stdin. See the second comment in https://unix.stackexchange.com/questions/338667/unix-systems-without-dev-stdin-dev-stdout-and-dev-stderr. I also logged into the community AIX machines and there is no /dev/stdin:
So although for redirection behaviour seems to be similar, the files do not actually exist in /dev. Given that the test depends on /dev/stdin, I'd suggest it just be skipped as it is for windows. |
@mhdawson Thanks!
I'm +1 |
9746ad1
to
d4d9120
Compare
Done. |
d4d9120
to
363020c
Compare
Pre land CI: https://ci.nodejs.org/job/node-test-commit/10154/ |
|
PR-URL: nodejs#13028 Reviewed-By: Refael Ackermann <[email protected]>
Landed in b3d1e3d |
PR-URL: #13028 Reviewed-By: Refael Ackermann <[email protected]>
The docs here claim that it is adding a new api... should this have been semver minor? |
ping |
ping @refack |
AFAICT this is $ echo "" | node -e "console.log(require('fs').realpathSync('/dev/stdin'))"
Error: ENOENT: no such file or directory, lstat '/proc/180/fd/pipe:[140]'
at Object.fs.lstatSync (fs.js:961:11)
at Object.realpathSync (fs.js:1629:21) so now it returns a sane value: $ echo "" | node -e "console.log(require('fs').realpathSync('/dev/stdin'))"
/proc/577/fd/pipe:[565] Documentation comment could have been "Pipe/Socket resolve support |
@refack this doesn't appear broken on v6.x right now |
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
fs
Currently
echo "" | node -e "require('fs').realpath('/dev/stdin', console.log)"
and
echo "" | node -e "console.log(require('fs').realpathSync('/dev/stdin'))"
are broken due to our logic of realpath and this patch changes node in a way to match python:
echo "" | python -c "import os; print(os.path.realpath('/dev/stdin'))"