Skip to content

Implemented deno.chmodSync for mac/linux os users. #673

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

Closed
wants to merge 4 commits into from
Closed

Implemented deno.chmodSync for mac/linux os users. #673

wants to merge 4 commits into from

Conversation

srijanreddy98
Copy link
Contributor

@srijanreddy98 srijanreddy98 commented Sep 4, 2018

I have implemented chmodSync for mac/linux os.
Prior art:
Go: func Chmod(name string, mode FileMode) error

Node: fs.chmod(file, mode, callback){

Python: os.chmod(path, mode);

pub fn set_permissions<P: AsRef>(path: P, perm: Permissions) -> Result<()>

Permissions struct in Rust doesn't allow anything apart from -r--r--r-- or -rw-rw-rw

js/os_test.ts Outdated
const path = "/README.md";
const mode = "777";
deno.chmodSync(path, mode);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to create a temp directory and use that for the chmod target.

js/os.ts Outdated
*
* chmodSync(path, mode);
*/
export function chmodSync(path: string, mode: string): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use an integer for the mode - as Node does - https://nodejs.org/api/fs.html#fs_file_modes

src/handlers.rs Outdated
.arg("-c")
.arg(final_cmd.to_string())
.output()
.expect("failed to execute process")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting a new process to do chmod is much too much overhead. Please call the syscall directly.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Nice start - but needs more work.

@srijanreddy98
Copy link
Contributor Author

I will start working on the suggested changes.

@kevinkassimo
Copy link
Contributor

@srijanreddy98 Looks like you pushed depot_tools_temp/ to the branch (639,880 new changes). Probably need to clean up

@srijanreddy98
Copy link
Contributor Author

@kevinkassimo I removed them, but build fails at LINK ./deno

src/handlers.rs Outdated
if cfg!(target_os = "windows") {
path_to_dynamic_lib = "/home/srijan/Documents/chmod.dll"; // This will change to the path where deno will be present
} else {
path_to_dynamic_lib = "/home/srijan/Documents/chmod.so"; // This will change to the path where deno will be present
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Srijan - Thanks for looking into this but we shouldn't need any DLL loading to make this work. I think everything is in Rust's std library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinkassimo I initially thought of using it but this method takes a permission struct which has only one method called set_readonly(x: bool). So you can only set permissions to -r--r--r-- or -rw-rw-rw-. So I was looking for other ways.

Copy link
Contributor

@kevinkassimo kevinkassimo Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srijanreddy98 then probably PermissionExt is what you are looking for.
I believe OpenOptionsExt could also be used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinkassimo will it work for windows?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srijanreddy98 It's unix only.

@ry
Copy link
Member

ry commented Sep 24, 2018

@piscisaureus How should chmod operate on windows?

src/handlers.rs Outdated
permissions.set_mode(mode);
let _result = fs::set_permissions(path, permissions)?;
Ok(None)
}()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems to be badly formatted. Please run ./tools/format.py

const filename = deno.makeTempDirSync() + "/test.txt";
deno.writeFileSync(filename, data, 0o666);
let fileInfo = deno.statSync(filename);
console.log(fileInfo.mode, 0o666); // This is printing 33206 438
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ry deno.statSync(filename).mode is not working properly.

Checkout the line 802 in the build log Here.
802: 33206 438. This is coming from the line console.log(fileInfo.mode, 0o666); on which I am commenting.
I had initially opened an issue #756. At that time it worked on travis. Now it is not working on travis also. Can you check if you are also having the same behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srijanreddy98 You might want to apply a mask (0o777). For example in python

oct(33206) == '0100666'
33206 & 0o777 == 0o666

@ry
Copy link
Member

ry commented Oct 26, 2018

@srijanreddy98 Sorry for letting this fall to the bottom - I was waiting on a discussion about windows support. I think simply having this being a no-op on windows is the right behavior (or at least acceptable for now). @kevinkassimo has cleaned it up in #1088. I will land there.
Thank you

@ry ry closed this Oct 26, 2018
hardfist pushed a commit to hardfist/deno that referenced this pull request Aug 7, 2024
`#[cppgc]` return values were added in
denoland/deno_core@a736d86
which made
creation of cppgc backed objects possible without direct access to V8
APIs.

This patch builds on top of that and adds `#[cppgc]` support for async
ops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants