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.writeFileSync options.mode not work when file already exists #1546

Closed
gemwuu opened this issue Aug 24, 2021 · 3 comments · Fixed by #1621
Closed

fs.writeFileSync options.mode not work when file already exists #1546

gemwuu opened this issue Aug 24, 2021 · 3 comments · Fixed by #1621

Comments

@gemwuu
Copy link

gemwuu commented Aug 24, 2021

echo 1 > a && ls -l a
# -rw-rw-r-- 1 admin admin 2 Aug 24 18:29 a

node -e "fs.writeFileSync('./a', 'echo world', {mode: 0o755})" && ls -l a
# -rw-rw-r-- 1 admin admin 10 Aug 24 18:29 a

./a
# bash: ./a: Permission denied

Even we specify the mode to be 0o755, fs.writeFileSync still doesn't change to file mode which is 0o644.

So the installer which uses fs.writeFileSync L63 won't make esbuild executable.

This is a default behavior on POSIX when trying to write Buffer to an existing file.

PR#1547 shall fix it.

@hyrious
Copy link

hyrious commented Aug 24, 2021

ref: nodejs/node#2249

@gemwuu gemwuu changed the title fs.writeFileSync options.mode not work fs.writeFileSync options.mode not work when file already exists Aug 24, 2021
@evanw
Copy link
Owner

evanw commented Aug 26, 2021

This is true. However, how does this behavior manifest when you install esbuild? What are the steps to reproduce the problem you are experiencing, and on what system?

@gemwuu
Copy link
Author

gemwuu commented Aug 26, 2021

This is true. However, how does this behavior manifest when you install esbuild? What are the steps to reproduce the problem you are experiencing, and on what system?

I cusomized a npm installer, it would change the esbuild/bin/esbuild to default 0o644 when writing files into disk, and esbuild postinstall tries to overwrite bin/esbuild using a platform-specific npm package (e.g. esbuild-linux-arm64).

In this case, bin/esbuild won't have the 0o755 pemissions, so it's better to chmod than writeFile with mode 0o755.

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

Successfully merging a pull request may close this issue.

3 participants