-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Remove uncommon functions from common module #17781
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
common.getTTYfd() is used in one test only. Move it's definition to that test and out of the common module.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -247,7 +247,24 @@ if (common.hasCrypto) { // eslint-disable-line crypto-check | |
|
|
||
| { | ||
| // Do our best to grab a tty fd. | ||
| const tty_fd = common.getTTYfd(); | ||
| function getTTYfd() { | ||
| const tty = require('tty'); | ||
| let tty_fd = 0; | ||
| if (!tty.isatty(tty_fd)) tty_fd++; | ||
| else if (!tty.isatty(tty_fd)) tty_fd++; | ||
| else if (!tty.isatty(tty_fd)) tty_fd++; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can someone explain to me how this works?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't write the code but I assume: The default file descriptors for I/O are stdin, stdout and stderr (0, 1 and 2 respectively). It's not always guaranteed to be the case, so we try the first 3 and then try
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was a cut-and-paste, I didn't write it, but yeah, it's not just hard to follow, but also buggy. If the first If 0 and 1 are not TTYs but 2 is, we won't get 2 (unless that's what's returned by the I think something more like this is what we want: let tty_fd = [0, 1, 2].find(tty.isatty);
if (tty_fd === undefined) {
try {
tty_fd = fs.openSync('/dev/tty');
} catch (e) {
// There aren't any tty fd's available to use.
return -1;
}
}
return tty_fd;(And while I'm in there fixing this function so it hopefully works correctly, I should probably refactor
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a commit here to fix this. PTAL. |
||
| else { | ||
| try { | ||
| tty_fd = fs.openSync('/dev/tty'); | ||
| } catch (e) { | ||
| // There aren't any tty fd's available to use. | ||
| return -1; | ||
| } | ||
| } | ||
| return tty_fd; | ||
| } | ||
|
|
||
| const tty_fd = getTTYfd(); | ||
| if (tty_fd >= 0) { | ||
| const tty_wrap = process.binding('tty_wrap'); | ||
| // fd may still be invalid, so guard against it. | ||
|
|
||
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.
Was this branch ever reached?
Uh oh!
There was an error while loading. Please reload this page.
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.
Nvm, 8be1259 is the answer.