-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
doc: document opening hidden files on Windows #15409
Conversation
doc/api/fs.md
Outdated
@@ -102,6 +102,11 @@ example `fs.readdirSync('c:\\')` can potentially return a different result than | |||
`fs.readdirSync('c:')`. For more information, see | |||
[this MSDN page][MSDN-Rel-Path]. | |||
|
|||
*Note:* On Windows opening existing hidden file using the `w` flag (either | |||
through `fs.open` or `fs.writeFile`) will fail with `EPERM`. You can work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nit: fs.open()
, fs.writeFile()
and fs.ftruncate()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be either opening an existing hidden file
or opening existing hidden files
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid the use of informal pronouns like you
in the docs
doc/api/fs.md
Outdated
*Note:* On Windows opening existing hidden file using the `w` flag (either | ||
through `fs.open` or `fs.writeFile`) will fail with `EPERM`. You can work | ||
around this by opening the file with the `a` flag and then using `fs.ftruncate` | ||
to clear the file contents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does ftruncate
rewind the current file position to the beginning?
doc/api/fs.md
Outdated
@@ -102,6 +102,11 @@ example `fs.readdirSync('c:\\')` can potentially return a different result than | |||
`fs.readdirSync('c:')`. For more information, see | |||
[this MSDN page][MSDN-Rel-Path]. | |||
|
|||
*Note:* On Windows opening existing hidden file using the `w` flag (either |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: comma after On Windows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there. Left a couple comments.
Updated, PTAL |
Ping @jasnell. I think your comments have been addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise.
doc/api/fs.md
Outdated
*Note:* On Windows, opening an existing hidden file using the `w` flag (either | ||
through `fs.open` or `fs.writeFile`) will fail with `EPERM`. Hidden files | ||
can be opened for writing with either `a` or `r+` flag. A call to | ||
`fs.truncate` can be used to reset the file contents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't truncate a file opened in 'a'
mode.
> var fd = fs.openSync('test.txt', 'a')
undefined
> fs.truncateSync(fd)
Error: EPERM: operation not permitted, ftruncate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, looks like on Windows you need to open the file with r+
for truncate
to work. That is unfortunate, there is no easy way to reproduce Linux behavior. One would need to call truncate
with filename, ignore the error if the file does not exists, and then open the file with a
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the best thing is to just document that?
@bzoz would you be so kind and address the comment? This is only blocked by that. |
Updated, PTAL |
Rather that opening the file twice, I think we should instead suggest opening in |
@seishun |
@bzoz |
Sure, but then it will be created by |
If we want to suggest only the approach that works for both existing and non-existing files, then |
Hm, file needs to exist to be "hidden". So maybe we should only describe |
Updated. PTAL |
Since the suggested approach now only works on existing files, perhaps it should say |
Landed in 4f1d548 |
PR-URL: #15409 Fixes: #14553 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
PR-URL: #15409 Fixes: #14553 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
PR-URL: nodejs/node#15409 Fixes: nodejs/node#14553 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
PR-URL: nodejs/node#15409 Fixes: nodejs/node#14553 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Fixes: #14553
Checklist
Affected core subsystem(s)
doc