Skip to content

Added implementation on set_permissions_nofollow for all primary platforms#158168

Open
asder8215 wants to merge 1 commit into
rust-lang:mainfrom
asder8215:windows_set_permissions_nofollow
Open

Added implementation on set_permissions_nofollow for all primary platforms#158168
asder8215 wants to merge 1 commit into
rust-lang:mainfrom
asder8215:windows_set_permissions_nofollow

Conversation

@asder8215

@asder8215 asder8215 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

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:

  • 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 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. 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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 20, 2026
@rustbot

rustbot commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 12 candidates
  • Random selection from Darksonn, Mark-Simulacrum, clarfonthey, jhpratt

@asder8215 asder8215 force-pushed the windows_set_permissions_nofollow branch from 3411717 to 96bc9a1 Compare June 20, 2026 07:00
@rust-log-analyzer

This comment has been minimized.

Comment thread library/std/src/sys/fs/hermit.rs Outdated
Comment thread library/std/src/sys/fs/uefi.rs Outdated
Comment thread library/std/src/fs/tests.rs Outdated
Comment thread library/std/src/fs/tests.rs
Comment thread library/std/src/sys/fs/motor.rs Outdated
}

pub fn set_perm_nofollow(path: &Path, perm: FilePermissions) -> io::Result<()> {
set_perm(path, perm)

@clarfonthey clarfonthey Jun 20, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Comment thread library/std/src/sys/fs/solid.rs Outdated
@clarfonthey

Copy link
Copy Markdown
Contributor

@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.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2026
@rustbot

rustbot commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot

rustbot commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@asder8215 asder8215 requested a review from clarfonthey June 21, 2026 07:27
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 21, 2026
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_set_permissions_nofollow branch from f9c87ed to feafe24 Compare June 21, 2026 08:24
@rust-log-analyzer

This comment has been minimized.

…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
@asder8215 asder8215 force-pushed the windows_set_permissions_nofollow branch from feafe24 to b286acf Compare June 21, 2026 08:51
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] gimli test:false 8.340
[RUSTC-TIMING] object test:false 11.694
warning: dropping unsupported crate type `dylib` for target `wasm32-wasip1`

error[E0425]: cannot find function `fchmodat` in crate `libc`
    --> library/std/src/sys/fs/unix.rs:1998:23
     |
1998 |                 libc::fchmodat(libc::AT_FDCWD, p.as_ptr(), perm.mode, libc::AT_SYMLINK_NOFOLLOW)
     |                       ^^^^^^^^
     |
    ::: /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.185/src/wasi/mod.rs:1027:5
     |
1027 |     pub fn fchmod(fd: c_int, mode: mode_t) -> c_int;
     |     ------------------------------------------------ similarly named function `fchmod` defined here
     |
help: a function with a similar name exists
     |
1998 -                 libc::fchmodat(libc::AT_FDCWD, p.as_ptr(), perm.mode, libc::AT_SYMLINK_NOFOLLOW)
1998 +                 libc::fchmod(libc::AT_FDCWD, p.as_ptr(), perm.mode, libc::AT_SYMLINK_NOFOLLOW)
     |

For more information about this error, try `rustc --explain E0425`.
[RUSTC-TIMING] std test:false 4.508
warning: `std` (lib) generated 1 warning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants