Skip to content
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: add default options for stat, fstat, and lstat #29114

Closed
wants to merge 2 commits into from

Conversation

@UziTech
Copy link
Contributor

commented Aug 14, 2019

Add default options to the function signatures for fs.stat, fs.fstat, and fs.lstat.

This allows a library to pass undefined to get the default options.

Fixes: #29113

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
@Trott

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

@@ -796,7 +796,7 @@ function readdirSync(path, options) {
return options.withFileTypes ? getDirents(path, result) : result;
}

function fstat(fd, options, callback) {
function fstat(fd, options = { bigint: false }, callback) {

This comment has been minimized.

Copy link
@Trott

Trott Aug 14, 2019

Member

Why not just options = {}? (Same below.)

This comment has been minimized.

Copy link
@UziTech

UziTech Aug 14, 2019

Author Contributor

I just copied fs/promises.js

async function fstat(handle, options = { bigint: false }) {

Should I use getOptions(options, {bigint: false}) to match the other functions?

This comment has been minimized.

Copy link
@joyeecheung

joyeecheung Aug 14, 2019

Member

getOptions() does a bunch of other things that do not fit these APIs (like accepting a string as the encoding option), using default arguments should be fine considering we do this for many other APIs as well.

@Trott

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

I seem to recall that we used to avoid default options like this because it would run slower than doing the equivalent in the first few lines of the function. But I don't know if that's no longer a problem or not (or if it never was an I'm imagining it). /ping @mscdex

@Trott

This comment has been minimized.

@Trott

This comment has been minimized.

Copy link
Member

commented Aug 14, 2019

Welcome @UziTech and thanks for the pull request!

@joyeecheung
Copy link
Member

left a comment

Can you add a test?

@UziTech

This comment has been minimized.

Copy link
Contributor Author

commented Aug 14, 2019

@joyeecheung I am not very familiar with the node codebase. Where would you like me to add the tests?

@UziTech

This comment has been minimized.

Copy link
Contributor Author

commented Aug 14, 2019

I think I found the right place. I added the tests to /test/parallel/test-fs-stat.js

@UziTech UziTech force-pushed the UziTech:patch-1 branch from ec474dc to 867edd1 Aug 14, 2019

@Trott
Trott approved these changes Aug 14, 2019
@nodejs-github-bot

This comment has been minimized.

@UziTech

This comment has been minimized.

Copy link
Contributor Author

commented Aug 15, 2019

I don't think the failed tests have anything to do with my code changes.

@nodejs-github-bot

This comment has been minimized.

@lpinca
lpinca approved these changes Aug 16, 2019
@Trott

This comment has been minimized.

Copy link
Member

commented Aug 16, 2019

Landed in 4111c57.

Thanks for the contribution! 🎉

@Trott Trott closed this Aug 16, 2019

Trott added a commit that referenced this pull request Aug 16, 2019
fs: add default options for *stat()
PR-URL: #29114
Fixes: #29113
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos added a commit that referenced this pull request Aug 19, 2019
fs: add default options for *stat()
PR-URL: #29114
Fixes: #29113
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
targos added a commit that referenced this pull request Aug 19, 2019
fs: add default options for *stat()
PR-URL: #29114
Fixes: #29113
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@targos targos referenced this pull request Aug 19, 2019
JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
fs: add default options for *stat()
PR-URL: nodejs#29114
Fixes: nodejs#29113
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
fs: add default options for *stat()
PR-URL: nodejs#29114
Fixes: nodejs#29113
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.