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 doesn't change the mode of existing file. #39859

Closed
gemwuu opened this issue Aug 24, 2021 · 4 comments
Closed

fs.writeFileSync doesn't change the mode of existing file. #39859

gemwuu opened this issue Aug 24, 2021 · 4 comments
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.

Comments

@gemwuu
Copy link

gemwuu commented Aug 24, 2021

Version

16.4.0

Platform

macOS

Subsystem

Big Sur(11.2.3)

What steps will reproduce the bug?

echo "echo 11" > a && ls -l a && ./a
node -e "fs.writeFileSync('./a', 'echo 1111', {mode: 0o755})" && ls -l a && ./a
-rw-r--r--  1 test  staff  8 Aug 24 19:04 a
a.sh: line 1: ./a: Permission denied
-rw-r--r--  1 test  staff  9 Aug 24 19:04 a
a.sh: line 2: ./a: Permission denied

How often does it reproduce? Is there a required condition?

no condition

What is the expected behavior?

should print 1111.

What do you see instead?

a.sh: line 2: ./a: Permission denied

Additional information

No response

@targos targos added the fs Issues and PRs related to the fs subsystem / file system. label Aug 24, 2021
@rayw000
Copy link
Contributor

rayw000 commented Aug 25, 2021

Same issues happen on fs.appendFile and fs.appendFileSync.

Let me handle this.

@targos
Copy link
Member

targos commented Aug 25, 2021

I'm not sure what the behavior is supposed to be but it doesn't seem like a bug. The mode is probably only used when a new file is created.
@nodejs/fs

@rayw000
Copy link
Contributor

rayw000 commented Aug 25, 2021

I'm not sure what the behavior is supposed to be but it doesn't seem like a bug. The mode is probably only used when a new file is created.
@nodejs/fs

Or, should we describe this in the document? Currently none of these functions say they will ignore mode option if the file exists. This may be surprising.

@targos targos added the doc Issues and PRs related to the documentations. label Aug 25, 2021
@gemwuu
Copy link
Author

gemwuu commented Aug 25, 2021

I'm not sure what the behavior is supposed to be but it doesn't seem like a bug. The mode is probably only used when a new file is created.
@nodejs/fs

Yes, When I looked into the source code L2153, writeFileSync call openSync firstly,which has explained in the doc, it shall make the POSIX syscall open.

@gemwuu gemwuu closed this as completed Aug 25, 2021
jasnell pushed a commit that referenced this issue Sep 3, 2021
PR-URL: #39881
Fixes: #39859
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
targos pushed a commit that referenced this issue Sep 4, 2021
PR-URL: #39881
Fixes: #39859
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
targos pushed a commit that referenced this issue Sep 6, 2021
PR-URL: #39881
Fixes: #39859
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
targos pushed a commit that referenced this issue Sep 6, 2021
PR-URL: #39881
Fixes: #39859
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@targos @gemwuu @rayw000 and others