-
Notifications
You must be signed in to change notification settings - Fork 30k
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
cli: accept /dev/stdin as input file on Linux #13130
Conversation
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.
suggestion
src/node_file.cc
Outdated
@@ -559,6 +560,9 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) { | |||
if (rc == 0) { | |||
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr); | |||
rc = !!(s->st_mode & S_IFDIR); | |||
if (rc == 0) { |
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.
Since this is a non hot-spot, I'd rather see an explicit if
and rc = 2
, similar to
if (rc == 0 && (s->st_mode & (S_IFIFO | S_IFSOCK))) {
rc = 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.
Sure, done
Added A question just for my information (since I'm not a posix expert): In the "simple" case |
When a process is piped, /dev/stdin will be a pipe (FIFO) normally.
But it seems in
(checks if
(is a socket, |
@ebraminio Thanks! Follow Up: So what is |
macOS probably has same stat but its difference and advantage is on the fact that its |
Will this make Is that useful or potentially risky? |
It's as bad as |
It is already possible on macOS and possibly [not tested] other BSD derivations anyway. |
lib/module.js
Outdated
@@ -195,6 +195,8 @@ Module._findPath = function(request, paths, isMain) { | |||
if (exts === undefined) | |||
exts = Object.keys(Module._extensions); | |||
filename = tryPackage(basePath, exts, isMain); | |||
} else if (rc === 2) { // Pipe or Socket |
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.
Nit: two spaces before the comment.
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.
Removed on new version as suitable comment on that version was something like neither file or directory which can be implied from the above.
src/node_file.cc
Outdated
@@ -559,6 +560,9 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) { | |||
if (rc == 0) { | |||
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr); | |||
rc = !!(s->st_mode & S_IFDIR); | |||
if (rc == 0 && (s->st_mode & (S_IFIFO | S_IFSOCK))) { |
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 100% convinced this is correct. Is there a reason you left out S_IFCHR?
My gut instinct is that the logic should look something like this:
if (S_ISREG(s->st_mode))
rc = 0;
else if (S_ISDIR(s->st_mode))
rc = 1;
else
rc = 2;
(Whether that compiles on Windows is left as an exercise to the reader.)
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.
That macro is not available but S_IFREG can be used it seems, done.
src/node_file.cc
Outdated
@@ -546,7 +546,8 @@ static void InternalModuleReadFile(const FunctionCallbackInfo<Value>& args) { | |||
} | |||
|
|||
// Used to speed up module loading. Returns 0 if the path refers to | |||
// a file, 1 when it's a directory or < 0 on error (usually -ENOENT.) | |||
// a file, 1 when it's a directory, 2 when is pipe or socket, or < 0 on |
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 to update the comment: "2 when it's anything else"
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.
Ops, done
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.
1 nit
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.
LGTM. A regression test would be nice, though.
As this is unix only unlike the other patch, a separate test is added and this no longer blocked on that. |
Unblocked, but rename the test to start with the subsystem you are testing, something like: |
Hmmm, the logic seems not OK, hopefully temporary closing |
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
cli
As mentioned above, tests will be added but for now, test it on Linux (macOS is OK) like this which with current version is broken:
make && echo "console.log(process.argv[2])" | ./node /dev/stdin --option-for-stdin-script