-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Added implementation on set_permissions_nofollow for all primary platforms
#158168
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -613,6 +613,66 @@ fn set_get_unix_permissions() { | |
| assert_eq!(mask & metadata1.permissions().mode(), 0o0777); | ||
| } | ||
|
|
||
| #[test] | ||
| fn set_get_permissions_nofollows() { | ||
| let tmpdir = tmpdir(); | ||
| let filename = tmpdir.join("set_get_unix_permissions_file"); | ||
| check!(File::create(&filename)); | ||
| let file_metadata = check!(fs::metadata(&filename)); | ||
| assert!(!file_metadata.permissions().readonly()); | ||
| let mut permission_bits = file_metadata.permissions(); | ||
| permission_bits.set_readonly(true); | ||
| let result = fs::set_permissions_nofollow(&filename, permission_bits); | ||
|
|
||
| cfg_select! { | ||
| any(windows, unix, target_os = "uefi", target_os = "solid_asp3", target_os = "motor") => { | ||
| assert_eq!(result.unwrap(), ()); | ||
| let metadata0 = check!(fs::metadata(&filename)); | ||
| assert!(metadata0.permissions().readonly()); | ||
| }, | ||
| _ => { | ||
| let error_kind = result.unwrap_err().kind(); | ||
| assert_eq!(error_kind, crate::io::ErrorKind::Unsupported); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Only Windows and Unix support `fs::set_permissions_nofollow` | ||
| #[test] | ||
| #[cfg(any(windows, unix))] | ||
| fn set_get_permissions_nofollows_symlink() { | ||
| #[cfg(not(windows))] | ||
| use crate::os::unix::fs::symlink; | ||
| #[cfg(windows)] | ||
| use crate::os::windows::fs::symlink_dir; | ||
|
|
||
| let tmpdir = tmpdir(); | ||
| let filename = tmpdir.join("set_get_unix_permissions_file"); | ||
| let symlink_name = tmpdir.join("set_get_unix_permissions"); | ||
| check!(File::create(&filename)); | ||
| #[cfg(not(windows))] | ||
| check!(symlink(&filename, &symlink_name)); | ||
| #[cfg(windows)] | ||
| check!(symlink_dir(&filename, &symlink_name)); | ||
|
|
||
| let sym_metadata = check!(fs::symlink_metadata(&symlink_name)); | ||
| let mut permission_bits = sym_metadata.permissions(); | ||
| permission_bits.set_readonly(true); | ||
| let result = fs::set_permissions_nofollow(&symlink_name, permission_bits); | ||
|
|
||
| cfg_select! { | ||
| any(target_os = "macos", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "espidf", target_os = "horizon") => { | ||
| assert_eq!(result.unwrap(), ()); | ||
| let metadata0 = check!(fs::symlink_metadata(&symlink_name)); | ||
| assert!(metadata0.permissions().readonly()); | ||
| }, | ||
| _ => { | ||
| let error_kind = result.unwrap_err().kind(); | ||
| assert_eq!(error_kind, crate::io::ErrorKind::Unsupported); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(windows)] | ||
| fn file_test_io_seek_read_write() { | ||
|
|
@@ -1330,6 +1390,29 @@ fn fchmod_works() { | |
| check!(file.set_permissions(p)); | ||
| } | ||
|
|
||
| #[test] | ||
|
Contributor
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. I assume you didn't mean to keep this in?
Contributor
Author
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. No, I did mean to keep this in. I templated this test off the two tests before this Which reminds me that I need to update documentation to mention that it uses
Contributor
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. I guess that the main confusion here is that aren't there platforms where this will just fail, e.g. ones without any permissions, like VexOS?
Contributor
Author
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. Now that you ask that, does CI run these tests on platforms like VexOS/UEFI? I know it checks if the code compiles on those platforms, but I haven't noticed if CI actually runs these tests on those platforms. This should definitely panic on certain lines like 1413. |
||
| fn fchmodat_works() { | ||
| let tmpdir = tmpdir(); | ||
| let file = tmpdir.join("in.txt"); | ||
|
|
||
| check!(File::create(&file)); | ||
| let attr = check!(fs::metadata(&file)); | ||
| assert!(!attr.permissions().readonly()); | ||
| let mut p = attr.permissions(); | ||
| p.set_readonly(true); | ||
| check!(fs::set_permissions_nofollow(&file, p.clone())); | ||
| let attr = check!(fs::metadata(&file)); | ||
| assert!(attr.permissions().readonly()); | ||
|
|
||
| match fs::set_permissions_nofollow(&tmpdir.join("foo"), p.clone()) { | ||
| Ok(..) => panic!("wanted an error"), | ||
| Err(..) => {} | ||
| } | ||
|
|
||
| p.set_readonly(false); | ||
| check!(fs::set_permissions_nofollow(&file, p)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn sync_doesnt_kill_anything() { | ||
| let tmpdir = tmpdir(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.