-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Show mode_t as octal in std::fs Debug impls #122812
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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::sys::pal::unix::fs::FilePermissions; | ||
|
||
#[test] | ||
fn test_debug_permissions() { | ||
for (expected, mode) in [ | ||
// typical directory | ||
("FilePermissions { mode: 0o040775 (drwxrwxr-x) }", 0o04_0775), | ||
// typical text file | ||
("FilePermissions { mode: 0o100664 (-rw-rw-r--) }", 0o10_0664), | ||
// setuid executable (/usr/bin/doas) | ||
("FilePermissions { mode: 0o104755 (-rwsr-xr-x) }", 0o10_4755), | ||
// char device (/dev/zero) | ||
("FilePermissions { mode: 0o020666 (crw-rw-rw-) }", 0o02_0666), | ||
// block device (/dev/vda) | ||
("FilePermissions { mode: 0o060660 (brw-rw----) }", 0o06_0660), | ||
// symbolic link | ||
("FilePermissions { mode: 0o120777 (lrwxrwxrwx) }", 0o12_0777), | ||
// fifo | ||
("FilePermissions { mode: 0o010664 (prw-rw-r--) }", 0o01_0664), | ||
// none | ||
("FilePermissions { mode: 0o100000 (----------) }", 0o10_0000), | ||
// unrecognized | ||
("FilePermissions { mode: 0o000001 }", 1), | ||
] { | ||
assert_eq!(format!("{:?}", FilePermissions { mode }), expected); | ||
} | ||
|
||
for (expected, mode) in [ | ||
// owner readable | ||
("FilePermissions { mode: 0o100400 (-r--------) }", libc::S_IRUSR), | ||
// owner writable | ||
("FilePermissions { mode: 0o100200 (--w-------) }", libc::S_IWUSR), | ||
// owner executable | ||
("FilePermissions { mode: 0o100100 (---x------) }", libc::S_IXUSR), | ||
// setuid | ||
("FilePermissions { mode: 0o104000 (---S------) }", libc::S_ISUID), | ||
// owner executable and setuid | ||
("FilePermissions { mode: 0o104100 (---s------) }", libc::S_IXUSR | libc::S_ISUID), | ||
// group readable | ||
("FilePermissions { mode: 0o100040 (----r-----) }", libc::S_IRGRP), | ||
// group writable | ||
("FilePermissions { mode: 0o100020 (-----w----) }", libc::S_IWGRP), | ||
// group executable | ||
("FilePermissions { mode: 0o100010 (------x---) }", libc::S_IXGRP), | ||
// setgid | ||
("FilePermissions { mode: 0o102000 (------S---) }", libc::S_ISGID), | ||
// group executable and setgid | ||
("FilePermissions { mode: 0o102010 (------s---) }", libc::S_IXGRP | libc::S_ISGID), | ||
// other readable | ||
("FilePermissions { mode: 0o100004 (-------r--) }", libc::S_IROTH), | ||
// other writeable | ||
("FilePermissions { mode: 0o100002 (--------w-) }", libc::S_IWOTH), | ||
// other executable | ||
("FilePermissions { mode: 0o100001 (---------x) }", libc::S_IXOTH), | ||
// sticky | ||
("FilePermissions { mode: 0o101000 (----------) }", libc::S_ISVTX), | ||
// other executable and sticky | ||
("FilePermissions { mode: 0o101001 (---------x) }", libc::S_IXOTH | libc::S_ISVTX), | ||
] { | ||
assert_eq!(format!("{:?}", FilePermissions { mode: libc::S_IFREG | mode }), expected); | ||
} | ||
|
||
for (expected, mode) in [ | ||
// restricted deletion ("sticky") flag is set, and search permission is not granted to others | ||
("FilePermissions { mode: 0o041000 (d--------T) }", libc::S_ISVTX), | ||
// sticky and searchable | ||
("FilePermissions { mode: 0o041001 (d--------t) }", libc::S_ISVTX | libc::S_IXOTH), | ||
] { | ||
assert_eq!(format!("{:?}", FilePermissions { mode: libc::S_IFDIR | mode }), expected); | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason for not using
Mode
as a field and continuing to derive the impls?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question — I started out this change that way in fact. Here is what it looks like: #123127. I switched to the way in this PR because I found the other one too invasive to the rest of the code in this module which involves arithmetic on the mode, but either way is fine with me. Let me know if you have a preference based on reading both. There is also a third possibility which omits those std::ops impls on Mode.