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

Add wrappers around fs.statSync and fs.lstatSync #745

Closed
nfischer opened this issue Jun 18, 2017 · 0 comments
Closed

Add wrappers around fs.statSync and fs.lstatSync #745

nfischer opened this issue Jun 18, 2017 · 0 comments
Assignees
Labels

Comments

@nfischer
Copy link
Member

We should consider adding wrapper methods around these functions:

// src/common.js

exports.statFollowLinks = fs.statSync.bind(fs);
exports.statNoFollowLinks = fs.lstatSync.bind(fs);

I'm usually not in favor of meaningless wrapper functions, but I think this could give us big wins for readability. We've had a few bugs (#733 is an example) that boil down to using the wrong fs.*statSync(). I personally have trouble remembering which one of those two follows links and which doesn't. Also, I don't give much thought when writing the code about whether or not to follow links, possibly introducing buggy behavior.

If we prefer our own aliases, we don't have to pay much performance penalty, but we remove these ambiguously named functions from our code. Also, since "FollowLinks" is in the name of the method, I'm more likely to double-check the behavior when writing the code. As a reviewer, this will remind me that we need to check behavior for both links and regular files.

We should also investigate writing a custom eslint rule to prohibit fs.statSync and fs.lstatSync in our code.

Finally, we need to scan the code base to make the replacements, possibly changing the link-behavior if we see an actual bug.

@freitagbr what do you think about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants