Repository navigation
fs::set_permissions_nofollow: Android support, test cleanup #163548
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
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,12 +613,13 @@ fn set_get_unix_permissions() { | |
| assert_eq!(mask & metadata1.permissions().mode(), 0o0777); | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "android"))] | ||
| /// Test set_permissions_nofollow on a regular file. | ||
| #[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(); | ||
|
|
@@ -648,12 +649,8 @@ fn set_get_permissions_nofollows() { | |
| } | ||
| } | ||
|
|
||
| // Only Windows and Unix support `fs::set_permissions_nofollow` | ||
| /// Test set_permissions_nofollow on a symlink. | ||
| #[test] | ||
| #[cfg(all( | ||
| any(windows, unix), | ||
| not(any(target_os = "espidf", target_os = "horizon", target_os = "wasi")) | ||
|
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 this is why you wanted to run
Member
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. I observed that My guess is that some of these were disabled because e.g. espidf does not support symlinks. However the comment does not say that and there are other symlink tests in this file and they are not gating espidf. So I'd rather leave it to an espidf maintainer to add the necessary cfg everywhere in this file, with proper comments. Same for horizon. I have not the slightest idea why wasi was added here, that one actually has handling in the implementation so it really should work. |
||
| ))] | ||
| fn set_get_permissions_nofollows_symlink() { | ||
| #[cfg(not(windows))] | ||
| use crate::os::unix::fs::symlink as symlink_file; | ||
|
|
@@ -667,14 +664,20 @@ fn set_get_permissions_nofollows_symlink() { | |
| check!(symlink_file(&filename, &symlink_name)); | ||
|
|
||
| let init_symlink_metadata = check!(fs::symlink_metadata(&symlink_name)); | ||
| let mut init_symlink_permissions = init_symlink_metadata.permissions(); | ||
|
|
||
| assert!(!init_symlink_metadata.permissions().readonly()); | ||
| let init_target_metadata = check!(fs::metadata(&symlink_name)); | ||
| let init_target_permissions = init_target_metadata.permissions(); | ||
| assert!(!init_target_metadata.permissions().readonly()); | ||
|
|
||
| // Set symlink permissions to readonly | ||
| init_symlink_permissions.set_readonly(true); | ||
| let result = fs::set_permissions_nofollow(&symlink_name, init_symlink_permissions); | ||
| let result = fs::set_permissions_nofollow(&symlink_name, { | ||
| let mut permissions = init_symlink_metadata.permissions(); | ||
| permissions.set_readonly(true); | ||
| permissions | ||
| }); | ||
|
|
||
| // This should not change the permissions of the target! | ||
| let after_target_metadata = check!(fs::metadata(&symlink_name)); | ||
| assert_eq!(after_target_metadata.permissions(), init_target_metadata.permissions()); | ||
|
|
||
| cfg_select! { | ||
| any( | ||
|
|
@@ -687,16 +690,11 @@ fn set_get_permissions_nofollows_symlink() { | |
| target_os = "nto", | ||
| target_os = "qnx" | ||
| ) => { | ||
| // On these systems, it's confirmed the symlink itself is marked readonly | ||
| // https://superuser.com/questions/1099634/change-permissions-symbolic-link-mac-os | ||
| assert_eq!(result.unwrap(), ()); | ||
|
|
||
| let after_target_metadata = check!(fs::metadata(&symlink_name)); | ||
| // We should expect the target file to not have its permission bits | ||
| // changed | ||
| assert_eq!(after_target_metadata.permissions(), init_target_permissions); | ||
|
|
||
| let after_symlink_metadata = check!(fs::symlink_metadata(&symlink_name)); | ||
| // On these systems, it's confirmed the symlink itself is marked readonly | ||
| // https://superuser.com/questions/1099634/change-permissions-symbolic-link-mac-os | ||
| assert!(after_symlink_metadata.permissions().readonly()); | ||
|
|
||
|
clarfonthey marked this conversation as resolved.
|
||
| // Reset the read-only bit under Windows 7: avoids the | ||
|
|
@@ -710,11 +708,7 @@ fn set_get_permissions_nofollows_symlink() { | |
| } | ||
| } | ||
| _ => { | ||
| let after_target_metadata = check!(fs::metadata(&symlink_name)); | ||
| // We should expect the target file to not have its permission bits | ||
| // changed | ||
| assert_eq!(after_target_metadata.permissions(), init_target_permissions); | ||
|
|
||
| // Everywhere else, this just fails. | ||
| let error_kind = result.unwrap_err().kind(); | ||
| assert_eq!(error_kind, crate::io::ErrorKind::Unsupported); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
I can't make sense of this comment as the test above runs on everything except for Android.
@asder8215 what did you mean when writing this comment?
View changes since the review
Uh oh!
There was an error while loading. Please reload this page.
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.
This might be a stale comment that I forgot to change.
I think, at the time, I didn't have
set_permissions_nofollowsupported for wasi (since it didn't havefchmodatsupport, but pretty sure it works with theopenatwith no follow flag) or this test specifically didn't run on wasi.Although technically, does this test may not run on wasi since I thought they use a different symlink create function, i.e.
symlink_path. You might want to add an import tosymlink_pathas asymlink_filegated towasi.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.
Nothing else in this file seems to special-case wasi so we probably just don't run these tests there.