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: use fs.access in fs.exists #18618

Closed
wants to merge 1 commit into from

Conversation

bzoz
Copy link
Contributor

@bzoz bzoz commented Feb 7, 2018

Uses fs.access() to implement fs.exists() functionality. Fixes a issue, when a file exists but user does not have privileges to do stat on the file.

Fixes: #17921

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

fs

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Feb 7, 2018
@bzoz
Copy link
Contributor Author

bzoz commented Feb 7, 2018

lib/fs.js Outdated
var req = new FSReqWrap();
req.oncomplete = cb;
binding.stat(pathModule.toNamespacedPath(path), req);
fs.access(path, fs.F_OK, cb);
Copy link
Member

@richardlau richardlau Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the behavior of fs.exists altered if callback is not a function? It looks like fs.access throws a TypeError in that case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cb is a function (it's defined on the line below) and it checks that callback is truthy.

lib/fs.js Outdated
var req = new FSReqWrap();
req.oncomplete = cb;
binding.stat(pathModule.toNamespacedPath(path), req);
fs.access(path, fs.F_OK, cb);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cb is a function (it's defined on the line below) and it checks that callback is truthy.

@BridgeAR
Copy link
Member

BridgeAR commented Feb 8, 2018

@bzoz this needs a rebase

@evanlucas
Copy link
Contributor

I feel like we tried to do this a few years ago (sometime around the time we added fs.access{Sync} and had to revert for some reason. I'll look back and see if I can find it

@bzoz
Copy link
Contributor Author

bzoz commented Feb 9, 2018

@evanlucas : maybe #4679 ?

@evanlucas
Copy link
Contributor

Oh well, I can't find it. Nevermind :]

@daynin
Copy link
Contributor

daynin commented Feb 10, 2018

@bzoz hi! Resolve the conflict pls

Uses fs.access to implement fs.exists functionality. Fixes a issue,
when a file exists but user does not have privileges to do stat on the
file.

Fixes: nodejs#17921

# Conflicts:
#	lib/fs.js
@bzoz
Copy link
Contributor Author

bzoz commented Feb 12, 2018

@bzoz
Copy link
Contributor Author

bzoz commented Feb 14, 2018

Failures look unrelated.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just left a suggestion.

if (ctx.errno !== undefined) {
return false;
}
fs.accessSync(path, fs.FS_OK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to use a cached fs.accessSync version. That way everything would still work, even if that function gets monkey patched.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be picked up in a separate PR, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do not use any reference so far and now introduce one, it might break. So I would rather do that in this PR, but it's not blocking for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I get the argument but monkeypatching fs is something that already a normal pattern. If we're going to fix it for one method, I'd rather fix it for all of them so there's less inconsistency. I'm happy either way tho. I was going to get this landed but will hold off for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, is it ok for me to land this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is OK to land but I personally would say it is better to use a cached version as we otherwise might introduce a potential issue that was not there before.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 16, 2018
@bzoz
Copy link
Contributor Author

bzoz commented Feb 22, 2018

@bzoz
Copy link
Contributor Author

bzoz commented Feb 22, 2018

Landed in d3955d1

@bzoz bzoz closed this Feb 22, 2018
bzoz added a commit that referenced this pull request Feb 22, 2018
Uses fs.access to implement fs.exists functionality. Fixes a issue,
when a file exists but user does not have privileges to do stat on the
file.

Fixes: #17921

PR-URL: #18618
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

bzoz added a commit to JaneaSystems/node that referenced this pull request Mar 28, 2018
Uses fs.access to implement fs.exists functionality. Fixes a issue,
when a file exists but user does not have privileges to do stat on the
file.

Fixes: nodejs#17921

PR-URL: nodejs#18618
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@bzoz
Copy link
Contributor Author

bzoz commented Mar 28, 2018

Backport in #19654

targos pushed a commit that referenced this pull request Apr 4, 2018
Uses fs.access to implement fs.exists functionality. Fixes a issue,
when a file exists but user does not have privileges to do stat on the
file.

Fixes: #17921

PR-URL: #18618
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Apr 4, 2018
Uses fs.access to implement fs.exists functionality. Fixes a issue,
when a file exists but user does not have privileges to do stat on the
file.

Fixes: #17921

Backport-PR-URL: #19654
PR-URL: #18618
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@targos targos added backported-to-v9.x and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. backport-requested-v9.x labels Apr 4, 2018
@targos targos mentioned this pull request Apr 4, 2018
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Uses fs.access to implement fs.exists functionality. Fixes a issue,
when a file exists but user does not have privileges to do stat on the
file.

Fixes: nodejs#17921

PR-URL: nodejs#18618
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

Should this be backported to v8.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

The 9.x backport does not land cleanly unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs.existsSync returns wrong value on windows if there are no permissions on the given file