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.access is not reliable in windows7 #7700

Closed
leftstick opened this issue Jul 13, 2016 · 7 comments
Closed

fs.access is not reliable in windows7 #7700

leftstick opened this issue Jul 13, 2016 · 7 comments
Labels
fs Issues and PRs related to the fs subsystem / file system. question Issues that look for answers.

Comments

@leftstick
Copy link

leftstick commented Jul 13, 2016

  • Version:
    v6.3.0
  • Platform:
    64-bit (Windows 7)

When performing following code:

var fs = require('fs');

fs.access('C:/Windows/System32/drivers/etc/hosts', fs.F_OK, function(err) {
    console.log('err', err); //err null
});

I am pretty sure i don't have write permission to the hosts file. But it resolves null to err.

Am i wrong with the usage?

@bnoordhuis
Copy link
Member

From the documentation:

fs.F_OK - File is visible to the calling process.

You probably want:

fs.W_OK - File can be written by the calling process.

Good luck.

@bnoordhuis bnoordhuis added question Issues that look for answers. fs Issues and PRs related to the fs subsystem / file system. labels Jul 13, 2016
@leftstick
Copy link
Author

@bnoordhuis , when switch to fs.W_OK, still have nothing to err

fs.access('C:/Windows/System32/drivers/etc/hosts', fs.W_OK, function(err) {
    console.log('err', err); //err null
});

but according to following screenshot, i don't have right to write this file

screen shot 2016-07-13 at 12 45 42 pm

@bnoordhuis
Copy link
Member

Node isn't aware of ACLs, it just looks at the file attributes. If the file doesn't have the read-only attribute set, it's considered writable.

@leftstick
Copy link
Author

@bnoordhuis So, you mean there is no way to check ACL on windows? A stable way?

@leftstick
Copy link
Author

Cause when i trying to write something into the hosts file, error thrown:

var fs = require('fs');

fs.access('C:/Windows/System32/drivers/etc/hosts', fs.W_OK, function(err) {
    console.log('err', err); //err null
});

fs.writeFile('C:/Windows/System32/drivers/etc/hosts', 'test', function(err) {
    console.log(err);//error occurs
});

screen shot 2016-07-13 at 1 10 55 pm

@bnoordhuis
Copy link
Member

you mean there is no way to check ACL on windows?

Not with node core. Maybe with a npm module.

Cause when i trying to write something into the hosts file, error thrown

That's how it should be. Look up 'TOCTOU'. Check-then-write is an anti-pattern.

@leftstick
Copy link
Author

Thanks for your time

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. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

2 participants