8000 mktemp: change directory permission after creation by 353fc443 · Pull Request #3471 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mktemp: change directory permission after creation #3471

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

Merged
merged 6 commits into from
May 25, 2022

Conversation

353fc443
Copy link
Contributor
@353fc443 353fc443 commented May 2, 2022

Closes #3466

@sylvestre
Copy link
Contributor

please add a test :)
thanks

@353fc443
Copy link
Contributor Author
353fc443 commented May 2, 2022

Writing one

@353fc443
Copy link
Contributor Author
353fc443 commented May 10, 2022

I tried writing a test, unfortunately that does't work

-->

@sylvestre
Copy link
Contributor

could you please give more detail on "that does't work" ? :)

@353fc443
Copy link
Contributor Author

@sylvestre I'm unable to get the permission of the newly created directory and compare with the 0o700

@jfinkels
Copy link
Collaborator

@353fc443 here is a test case you can add to the tests/by-util/test_mktemp.rs file. (There may be a similar test that can work for Windows as well.)

#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;

#[cfg(unix)]
#[test]
fn test_directory_permissions() {
    let (at, mut ucmd) = at_and_ucmd!();
    let result = ucmd.args(&["-d", "XXX"]).succeeds();
    let dirname = result.no_stderr().stdout_str().trim_end();
    assert_matches_template!("XXX", dirname);
    let metadata = at.metadata(dirname);
    assert!(metadata.is_dir());
    assert_eq!(metadata.permissions().mode(), 0o700);
}

@353fc443
Copy link
Contributor Author

@jfinkels Thanks I'll add the test and push it again!

@353fc443
Copy link
Contributor Author
353fc443 commented May 16, 2022

@jfinkels The test doesn't seem to work

failures:

---- test_mktemp::test_directory_permissions stdout ----
current_directory_resolved:
run: /Users/user/coreutils/target/debug/coreutils mktemp -d XXX
thread 'test_mktemp::test_directory_permissions' panicked at 'assertion failed: `(left == right)`
  left: `16832`,
 right: `448`', /Users/user/coreutils/tests/by-util/test_mktemp.rs:498:5

Tested on Macos

Edit: Can we use

assert_eq!(metadata.permissions().mode(), 0o40700);

instead of

assert_eq!(metadata.permissions().mode(), 0o700);

@353fc443 353fc443 force-pushed the mktemp-set-dir-mode branch from 1dc0281 to b84c1b2 Compare May 16, 2022 18:21
@353fc443 353fc443 force-pushed the mktemp-set-dir-mode branch from 04bedd2 to 2086d04 Compare May 17, 2022 04:58
@jfinkels
Copy link
Collaborator

Yes, looks like you were able to fix up the test that way. Great, thanks.

1 similar comment
@jfinkels
Copy link
Collaborator

Yes, looks like you were able to fix up the test that way. Great, thanks.

@353fc443
Copy link
Contributor Author

@sylvestre any suggestions?

@sylvestre
Copy link
Contributor

nope, this is great, thanks for the ping :)

@sylvestre sylvestre merged commit fa57760 into uutils:main May 25, 2022
@353fc443 353fc443 deleted the mktemp-set-dir-mode branch May 25, 2022 14:00
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.

mktemp: should create directory with mode 700 but doesn't
3 participants
0