denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.89k stars 5.35k forks source link

chmod doesn't work on Windows #4357

Open cknight opened 4 years ago

cknight commented 4 years ago

In Node, the following is observed on Windows:

const fs = require('fs');
fs.chmodSync('test_file.txt', 0o000);  //makes the file read-only
fs.chmodSync('test_file.txt', 0o777);  //makes the file writable

However, in Deno (v0.36.0) no file mode I tested changed the read-only attribute in any way (including the above two file modes).

From the Node docs:

on Windows only the write permission can be changed, and the distinction among the permissions of group, owner or others is not implemented.

Windows is not mentioned in the Deno docs.

It would be good if Deno could manipulate the read-only attribute of Windows files and specifically call out Windows quirks in the documentation for chmod.

dubiousjim commented 4 years ago

Sounds reasonable.

Should presumably also apply to the soon-to-be added mode option on open (#4289, should be merged soon) and truncate (#4288, waiting on some other PRs). Perhaps also the mode option on mkdir, but I've got little Windows experience so I don't know if they accept/honor the read-only attribute on directories.

Should the API be that 0o000 and 0o777 are required to change these attributes, and other values are ignored? Or that other values throw an error? Or that only the user-write bit (0o200) has an effect, and other bits are ignored?

dubiousjim commented 4 years ago

Of course, calling truncate and open with a read-only mode are guaranteed to either be ignored (if the file already exists) or fail (because you can't write to a file you're creating with read-only permissions). Still if the mode arguments are interpreted a given way on Windows for chmod, they should be interpreted the same way here too.

I guess it shouldn't be an error to open(path, {read:true, write:false, create:true, mode:0o400}). But if the file is created, it's going to be an empty read-only file, so this won't generally be useful.

cknight commented 4 years ago

Should the API be that 0o000 and 0o777 are required to change these attributes, and other values are ignored? Or that other values throw an error? Or that only the user-write bit (0o200) has an effect, and other bits are ignored?

I think the way node handles this is that only the user write-bit is honored. In my example 0o000 and 0o777 were arbitrary. 0o077 and 0o007 both behave as per 0o000 for example. Caveat, my access to a windows test box is limited, so I'm going off memory here.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

TradeIdeasPhilip commented 3 years ago

I see similar issues in Deno.writeTextFile(). I'm setting the mode to 0o444 (read only). The file is created and filled correctly. But the permissions are wrong. They are "-rw-r--r--" (644) according to git bash, and all permissions for the current use according to Windows file explorer.

I should have created a read only file. Barring that I should have gotten an exception or at least seen more details in the documentation.

martin-braun commented 2 years ago

It would be nice if Deno.chmod would allow to change read permissions on Windows, so Deno tests could include file access tests on Windows as well.