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.writeFile" with mode 0o777 doesn't work as expected #1104

Closed
ysmood opened this issue Mar 9, 2015 · 3 comments
Closed

"fs.writeFile" with mode 0o777 doesn't work as expected #1104

ysmood opened this issue Mar 9, 2015 · 3 comments

Comments

@ysmood
Copy link

ysmood commented Mar 9, 2015

Sample code:

var fs;

fs = require('fs');

try {
  fs.unlinkSync('a');
} catch (_error) {}

fs.writeFileSync('a', 'ok', {
  mode: 0o777
});
console.log(fs.statSync('a').mode.toString(8));
// output => 0o755

fs.chmodSync('a', 0o777);
console.log(fs.statSync('a').mode.toString(8));
// output => 0o777

It should output 0o777. But I get 0o755.
If I use the fs.chmod to change mode, everything will go well.

@bnoordhuis
Copy link
Member

That's the umask at work:

> (0o777 & ~process.umask()).toString(8)
'755'

Not a bug, it's just the way UNIX permissions work.

@ysmood
Copy link
Author

ysmood commented Mar 9, 2015

@bnoordhuis But why chmod doesn't follow the umask?

@bnoordhuis
Copy link
Member

@ysmood Because the umask applies to just a handful of functions (open, mkdir, etc.)

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

No branches or pull requests

2 participants