doc: document opening hidden files on Windows#15409
doc: document opening hidden files on Windows#15409bzoz wants to merge 5 commits intonodejs:masterfrom
Conversation
doc/api/fs.md
Outdated
| [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.
A nit: fs.open(), fs.writeFile() and fs.ftruncate()?
There was a problem hiding this comment.
Should be either opening an existing hidden file or opening existing hidden files.
There was a problem hiding this comment.
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.
Does ftruncate rewind the current file position to the beginning?
doc/api/fs.md
Outdated
| `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 |
jasnell
left a comment
There was a problem hiding this comment.
Almost there. Left a couple comments.
|
Updated, PTAL |
|
Ping @jasnell. I think your comments have been addressed. |
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.
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, ftruncateThere was a problem hiding this comment.
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.
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 <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #15409 Fixes: #14553 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: nodejs/node#15409 Fixes: nodejs/node#14553 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: nodejs/node#15409 Fixes: nodejs/node#14553 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Nikolai Vavilov <vvnicholas@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Fixes: #14553
Checklist
Affected core subsystem(s)
doc