Added implementation on set_permissions_nofollow for all primary platforms#158168
Added implementation on set_permissions_nofollow for all primary platforms#158168asder8215 wants to merge 1 commit into
set_permissions_nofollow for all primary platforms#158168Conversation
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
3411717 to
96bc9a1
Compare
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| pub fn set_perm_nofollow(path: &Path, perm: FilePermissions) -> io::Result<()> { | ||
| set_perm(path, perm) |
There was a problem hiding this comment.
Similar to UEFI, I would swap the method bodies here, so that set_perm defers to set_perm_nofollow plus a comment that says symlinks aren't supported.
|
@rustbot author CI failure appears to be a simple typo but I also left some feedback on other stuff to fix. Otherwise, implementation looks good, although I would add an extra comment on the tracking issue once this is merged to have some Windows folks double-check that opening all reparse points in this method doesn't do anything we don't want, since that technically includes more than just symlinks. It should work in pretty much all normal use cases, just want to double-check the edge cases before stabilisation. |
|
Reminder, once the PR becomes ready for a review, use |
96bc9a1 to
f9c87ed
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f9c87ed to
feafe24
Compare
This comment has been minimized.
This comment has been minimized.
feafe24 to
b286acf
Compare
This comment has been minimized.
This comment has been minimized.
b286acf to
14df6fa
Compare
This comment has been minimized.
This comment has been minimized.
14df6fa to
7029495
Compare
…=<try> Added implementation on `set_permissions_nofollow` for all primary platforms try-job: dist-various-* try-job: test-various try-job: aarch64-apple
|
@rustbot review I'll do another pass on review later and then we should be good to merge this, hopefully. |
| #[cfg(not(any(target_os = "espidf", target_os = "horizon")))] | ||
| { | ||
| use crate::os::wasi::fs::OpenOptionsExt; | ||
| options.custom_flags(libc::O_NOFOLLOW); | ||
| } | ||
|
|
There was a problem hiding this comment.
This is just dead code, yeah?
There was a problem hiding this comment.
Sorry, rephrase: the code in this block is unconditionally included because the cfg should be redundant.
|
Code looks good, r=me minus one comment. |
…pported (windows, unix, uefi, etc.); modified the Unix implementation to use fchmodat instead of open + fchmod; clarified documentations for set_permissions_nofollow; added a test case for set_permissions_nofollow
4efd835 to
cdad583
Compare
|
|
@bors r=clarfonthey |
|
@asder8215: 🔑 Insufficient privileges: not in review users |
|
Is that not how it works? |
|
(delegate try only allows try commands, not r+) @bors r+ rollup=iffy Failed before, tests passed now, still cautious. |
Oh got you. I think I just noticed in other PRs in the past with reviewers saying r=me and then the PR author run bors command with r=<person who gave r=me>. I don't know if that's what r=me means, but that's what I thought it allowed unprivileged users to do. |
…nofollow, r=clarfonthey Added implementation on `set_permissions_nofollow` for all primary platforms For context, this PR is related to the tracking issue for [`std::fs::set_permissions_nofollow`](rust-lang#141607). This PR does a few different things: * Windows support is provided for `std::fs::set_permissions_nofollow`. On Windows, it uses `OpenOptions::open` with the custom flag `FILE_FLAG_OPEN_REPARSE_POINT` enabled and then sets the permissions on the reparse point directly. All other platforms (hermit, motor, solid, uefi, etc.) defer to what `fs::set_permissions` does since symlinks aren't supported on those platforms, so they effectively do the same thing. * The implementation for Unix was modified to use [`fchmodat`](https://linux.die.net/man/2/fchmodat) instead of doing two separate calls (`open` and then `fchmod` via `OpenOptions`). * Because the previous implementations actually used `fchmod` instead of `chmod` underneath the hood (as that's what `File::set_permissions`, which is not to be confused with `fs::set_permissions` as that does use `chmod`, does underneath the hood), it actually had some incorrect documentation about the error returned by `fchmod` on symlinks. Instead of `io::ErrorKind::FilesystemLoop`, it returns `io::ErrorKind::InvalidInput`. You can read the documentation for [`fchmod`](https://pubs.opengroup.org/onlinepubs/009696699/functions/fchmod.html). `fchmodat` does effectively the same thing as the `open` + `fchmod` combo, but it does return a different error, `io::ErrorKind::Unsupported`, that makes more sense. Regardless, I corrected the documentation for `std::fs::set_permissions_nofollow` and added a lot more clarifying information. * A test case has been added to verify if `set_permissions_nofollow` is operating correctly. cc @ChrisDenton and @lolbinarycat
…nofollow, r=clarfonthey Added implementation on `set_permissions_nofollow` for all primary platforms For context, this PR is related to the tracking issue for [`std::fs::set_permissions_nofollow`](rust-lang#141607). This PR does a few different things: * Windows support is provided for `std::fs::set_permissions_nofollow`. On Windows, it uses `OpenOptions::open` with the custom flag `FILE_FLAG_OPEN_REPARSE_POINT` enabled and then sets the permissions on the reparse point directly. All other platforms (hermit, motor, solid, uefi, etc.) defer to what `fs::set_permissions` does since symlinks aren't supported on those platforms, so they effectively do the same thing. * The implementation for Unix was modified to use [`fchmodat`](https://linux.die.net/man/2/fchmodat) instead of doing two separate calls (`open` and then `fchmod` via `OpenOptions`). * Because the previous implementations actually used `fchmod` instead of `chmod` underneath the hood (as that's what `File::set_permissions`, which is not to be confused with `fs::set_permissions` as that does use `chmod`, does underneath the hood), it actually had some incorrect documentation about the error returned by `fchmod` on symlinks. Instead of `io::ErrorKind::FilesystemLoop`, it returns `io::ErrorKind::InvalidInput`. You can read the documentation for [`fchmod`](https://pubs.opengroup.org/onlinepubs/009696699/functions/fchmod.html). `fchmodat` does effectively the same thing as the `open` + `fchmod` combo, but it does return a different error, `io::ErrorKind::Unsupported`, that makes more sense. Regardless, I corrected the documentation for `std::fs::set_permissions_nofollow` and added a lot more clarifying information. * A test case has been added to verify if `set_permissions_nofollow` is operating correctly. cc @ChrisDenton and @lolbinarycat
Rollup of 17 pull requests Successful merges: - #158168 (Added implementation on `set_permissions_nofollow` for all primary platforms) - #138618 (Support using const pointers in asm `const` operand) - #157962 (Function item should not be used as const arg) - #158404 (trait_solver: normalize next-gen region constraints) - #158709 (rustdoc: warn on improperly interleaved HTML/MD) - #159720 (document #[global_allocator] constraints) - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled) - #159740 (reuse regular exported_non_generic_symbols logic in Miri) - #159780 (check `extern "custom"` function pointers) - #159786 (rustdoc-js: ignore editor temp files in test folder discovery) - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new) - #155388 (stepping into where-clauses during normalization may be productive) - #155914 (when bailing on ambiguity, don't force other results to ambig) - #159411 ([rustdoc] Correctly handle output options with --show-coverage) - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`) - #159809 (Avoid `#[target_features]`) - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
Yeah, bors only responds to @ mentions, so, this is just a syntax that folks use to clarify that it's okay to merge with the review on their behalf. It's all confusing and being a relatively new team member myself I'm also just working off of things I've noticed, so, you're not too far off. Either way, hopefully merge succeeds this time, and thank you for putting the work in! |
|
|
This pull request was unapproved. This PR was contained in a rollup (#159872), which was unapproved. |
|
Kind of incredible how every platform seems to handle this differently, somehow. |
View all comments
For context, this PR is related to the tracking issue for
std::fs::set_permissions_nofollow. This PR does a few different things:std::fs::set_permissions_nofollow. On Windows, it usesOpenOptions::openwith the custom flagFILE_FLAG_OPEN_REPARSE_POINTenabled and then sets the permissions on the reparse point directly. All other platforms (hermit, motor, solid, uefi, etc.) defer to whatfs::set_permissionsdoes since symlinks aren't supported on those platforms, so they effectively do the same thing.fchmodatinstead of doing two separate calls (openand thenfchmodviaOpenOptions).fchmodinstead ofchmodunderneath the hood (as that's whatFile::set_permissions, which is not to be confused withfs::set_permissionsas that does usechmod, does underneath the hood), it actually had some incorrect documentation about the error returned byfchmodon symlinks. Instead ofio::ErrorKind::FilesystemLoop, it returnsio::ErrorKind::InvalidInput. You can read the documentation forfchmod.fchmodatdoes effectively the same thing as theopen+fchmodcombo, but it does return a different error,io::ErrorKind::Unsupported, that makes more sense. Regardless, I corrected the documentation forstd::fs::set_permissions_nofollowand added a lot more clarifying information.set_permissions_nofollowis operating correctly.cc @ChrisDenton and @lolbinarycat