Repository navigation
Can't open hidden files in 'w' mode on Windows - document, fix, or do nothing? #14553
Description
Activity
- addeddiscussIssues opened for discussion and feedback.Issues opened for discussion and feedback.fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
on Jul 31, 2017 Does Node.js really have to match CRT's behavior here?
I'm not 100% sure but reading
fs__open()in deps/uv/src/win/fs.c (which uses the CreateFile NT API, not the CRT), I don't see anything that suggests it's a policy enforced by libuv.It doesn't enforce it explicitly, no. It just never passes the
FILE_ATTRIBUTE_HIDDENflag, causing CreateFile to fail when called on a hidden file.I don't know if that is fixable. Passing it by default is not an option and retrying the CreateFile() call on error is race-y. All signs seem to point to 'documentation fix.'
It seems like the only way to write to hidden files (without setting
FILE_ATTRIBUTE_HIDDEN) is by setting the disposition to eitherTRUNCATE_EXISTINGorCREATE_NEW, and I don't think it is possible to use these values infs.open()😞Hm, does that mean
'wx'instead of'w'works?Passing it by default is not an option
Why not?
FILE_ATTRIBUTE_HIDDENworks for both hidden and non-hidden files.Hm, does that mean 'wx' instead of 'w' works?
No, 'wx' maps to
O_TRUNC | O_CREAT | O_WRONLY | O_EXCL, which maps toCREATE_NEW, which fails if the file already exists.Why not?
FILE_ATTRIBUTE_HIDDENworks for both hidden and non-hidden files.But won't this cause new files to be hidden?
Indeed it does... 🤦♂️
So, what is the consensus here? Documentation fix? Any volunteers?
- added a commit that references this issue
on Sep 14, 2017 Yes, it is.
So the question at hand is whether we want to deviate from CRT here or not. If we do, this needs an upstream implementation, and I am not sure an atomic solution exists.
- added a commit that references this issue
on Oct 23, 2017 - added a commit that references this issue
on Oct 26, 2017 - added a commit that references this issue
on Dec 7, 2017 - added a commit that references this issue
on Jul 27, 2026
Trying to open a hidden file on Windows in 'w' mode throws
EPERM:This matches the behavior of Microsoft C runtime library:
Output if "hidden.txt" is hidden:
And it matches the behavior of Python since it purportedly uses
_wfopenunder the hood:However, this behavior has caused at least two issues down the road:
So, my questions are: