-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
mkdir: fixed not respecting set umask #3150
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
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ea175ce
mkdir: permissions respects umask
pyoky 65a45ae
Merge branch 'main' of github.com:pyoky/coreutils
pyoky 6db5bf1
Merge branch 'uutils:main' into mkdir-fix
pyoky b8c0a87
mkdir: fixed permissions behavior with umask
pyoky 8ffe367
test/mkdir: added testing for umask compliance
pyoky 553c22d
test/mkdir: reverted mkdir testing delete
pyoky fe9e9e6
test/mkdir: made umask variable mode_t
pyoky 31d91f3
test/mkdir: fixed assert types to both mode_t
pyoky 25f0423
Merge branch 'main' into mkdir-fix
sylvestre 9dea9b4
Merge branch 'main' into mkdir-fix
sylvestre 8108fb1
Merge branch 'uutils:main' into mkdir-fix
pyoky 9837072
test/mkdir: formatting compliance
pyoky ea592e5
Merge branch 'main' into mkdir-fix
pyoky 200adc9
Merge branch 'main' into mkdir-fix
sylvestre 9a76f3b
tests/mkdir: reduced tested permission combinations
pyoky 12ad0f0
Fix clippy
sylvestre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
use crate::common::util::*; | ||
#[cfg(not(windows))] | ||
use std::os::unix::fs::PermissionsExt; | ||
#[cfg(not(windows))] | ||
extern crate libc; | ||
#[cfg(not(windows))] | ||
use self::libc::{mode_t, umask}; | ||
|
||
static TEST_DIR1: &str = "mkdir_test1"; | ||
static TEST_DIR2: &str = "mkdir_test2"; | ||
|
@@ -13,6 +17,8 @@ static TEST_DIR8: &str = "mkdir_test8/mkdir_test8_1/mkdir_test8_2"; | |
static TEST_DIR9: &str = "mkdir_test9/../mkdir_test9_1/../mkdir_test9_2"; | ||
static TEST_DIR10: &str = "mkdir_test10/."; | ||
static TEST_DIR11: &str = "mkdir_test11/.."; | ||
#[cfg(not(windows))] | ||
static TEST_DIR12: &str = "mkdir_test12"; | ||
|
||
#[test] | ||
fn test_mkdir_mkdir() { | ||
|
@@ -151,3 +157,26 @@ fn test_mkdir_trailing_dot() { | |
let result = scene2.cmd("ls").arg("-al").run(); | ||
println!("ls dest {}", result.stdout_str()); | ||
} | ||
|
||
#[test] | ||
#[cfg(not(windows))] | ||
fn test_umask_compliance() { | ||
fn test_single_case(umask_set: mode_t) { | ||
let (at, mut ucmd) = at_and_ucmd!(); | ||
|
||
let original_umask = unsafe { umask(umask_set) }; | ||
|
||
ucmd.arg(TEST_DIR12).succeeds(); | ||
let perms = at.metadata(TEST_DIR12).permissions().mode() as mode_t; | ||
|
||
assert_eq!(perms, (!umask_set & 0o0777) + 0o40000); // before compare, add the set GUID, UID bits | ||
unsafe { | ||
umask(original_umask); | ||
} // set umask back to original | ||
} | ||
|
||
for i in 0o0..0o027 { | ||
// tests all permission combinations | ||
Comment on lines
+178
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not all the possible permission settings. That's fine, let's just make sure the comment matches the code. |
||
test_single_case(i as mode_t); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.