Skip to content
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

nushell: chmod functionality #5328

Open
KAAtheWiseGit opened this issue Sep 27, 2023 · 4 comments
Open

nushell: chmod functionality #5328

KAAtheWiseGit opened this issue Sep 27, 2023 · 4 comments

Comments

@KAAtheWiseGit
Copy link
Contributor

Both mkdir and install seem to use their own slightly different version of the chmod function. And neither have the detailed logic of the chmod crate. Should there be a function chmod function in uucore? Or is there a reason to keep them separate?

@KAAtheWiseGit KAAtheWiseGit changed the title chmod function chmod functionality Sep 27, 2023
@tertsdiepraam
Copy link
Member

Let's see. I assume your talking about these parts:

https:/uutils/coreutils/blob/main/src/uu/install/src/mode.rs (the whole file)

and

#[cfg(any(unix, target_os = "redox"))]
fn chmod(path: &Path, mode: u32) -> UResult<()> {
use std::fs::{set_permissions, Permissions};
use std::os::unix::fs::PermissionsExt;
let mode = Permissions::from_mode(mode);
set_permissions(path, mode)
.map_err_context(|| format!("cannot set permissions {}", path.quote()))
}
#[cfg(windows)]
fn chmod(_path: &Path, _mode: u32) -> UResult<()> {
// chmod on Windows only sets the readonly flag, which isn't even honored on directories
Ok(())
}

and I guess also this function from chmod:

fn change_file(&self, fperm: u32, mode: u32, file: &Path) -> Result<(), i32> {

Additionally they all have some code for parsing the mode.


Yeah, I think it would be nice to combine these as much as possible! As long as they really are compatible and don't use, for example, slightly different formats for the mode.

@KAAtheWiseGit
Copy link
Contributor Author

I went into the GNU's coreutils source, and here is what I found:

mkdir, install, and chmod use mode_adjust from modechange.h from gnulib to handle file modes. So, at least the core logic should be the same. I am trying to discern the high-level logic at the moment.

And I also found this, which is just delightful:

mkdir -p --mode=... only applies the mode to the right-most directory. Any parent directories are created with 'u+wx' modified by umask. If you want to control the mode for all created dirs, you can use a umask like (umask u=rwx,go=rx; mkdir -p dir1/dir2/dir3).

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Sep 27, 2023

I went into the GNU's coreutils source

Please don't do that. We can't base our code on GNU's code directly, because of license reasons. We have to base our implementation on the output, tests and documentation.

@KAAtheWiseGit
Copy link
Contributor Author

Got it. Somewhat thankfully, I couldn't figure it out, so I went to the documentation.

@sylvestre sylvestre changed the title chmod functionality nushell: chmod functionality Oct 1, 2023
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

No branches or pull requests

2 participants