In Node, file modes (e.g. for fs.open) are defined in the terms of the POSIX world (a three-digit octal value). However, that does not map to how Windows does things. Windows does not have such tight coupling between user permissions and the filesystem. Windows' OpenFile
function does not even have any related parameters. But from what I gathered so far, they are not entirely ignored either.
Is there any explanation on how to use Node file modes on Windows?
Take a look at the source. It seems like the only thing they are doing is setting FILE_ATTRIBUTE_READONLY based on whether the file is writeable or not.
if (flags & _O_CREAT) {
if (!((req->mode & ~current_umask) & _S_IWRITE)) {
attributes |= FILE_ATTRIBUTE_READONLY;
}
}
The notes on fs.chmod are interesting as well.
/* Todo: st_mode should probably always be 0666 for everyone. We might also
* want to report 0777 if the file is a .exe or a directory.
*
* Currently it's based on whether the 'readonly' attribute is set, which
* makes little sense because the semantics are so different: the 'read-only'
* flag is just a way for a user to protect against accidental deleteion, and
* serves no security purpose. Windows uses ACLs for that.
*
* Also people now use uv_fs_chmod() to take away the writable bit for good
* reasons. Windows however just makes the file read-only, which makes it
* impossible to delete the file afterwards, since read-only files can't be
* deleted.
*
* IOW it's all just a clusterfuck and we should think of something that
* makes slighty more sense.
*
* And uv_fs_chmod should probably just fail on windows or be a total no-op.
* There's nothing sensible it can do anyway.
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With