Skip to content

Refactored docs for std::fs::set_permissions_nofollow + fix BSD-based systems to use fchmodat with AT_SYMLINK_NOFOLLOW flag - #160170

Open
asder8215 wants to merge 4 commits into
rust-lang:mainfrom
asder8215:docs_set_perms_nofollow
Open

Refactored docs for std::fs::set_permissions_nofollow + fix BSD-based systems to use fchmodat with AT_SYMLINK_NOFOLLOW flag#160170
asder8215 wants to merge 4 commits into
rust-lang:mainfrom
asder8215:docs_set_perms_nofollow

Conversation

@asder8215

@asder8215 asder8215 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

View all comments

This PR refactors documentations for std::fs::set_permissions_nofollow and fixes BSD-based systems + Android to use fchmodat with AT_SYMLINK_NOFOLLOW flag (instead of no flag set) and refactors all other platforms to defer to OpenOptions with O_NOFOLLOW behavior.

r? @clarfonthey
Since they looked at the original set_permissions_nofollow PR I made

cc @RalfJung

@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 Jul 29, 2026
Comment thread library/std/src/fs.rs Outdated
@clarfonthey

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d24bee2 has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2026
Comment thread library/std/src/fs.rs Outdated
@RalfJung

Copy link
Copy Markdown
Member

@bors r-

Sorry I have a question :)

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 29, 2026
@rust-bors

rust-bors Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@clarfonthey

Copy link
Copy Markdown
Contributor

r? RalfJung since you're mostly reviewing already

@rustbot

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@asder8215
asder8215 force-pushed the docs_set_perms_nofollow branch from d24bee2 to 82ff1cb Compare July 29, 2026 21:45
@asder8215
asder8215 requested a review from RalfJung July 29, 2026 21:46
@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 Jul 29, 2026
@asder8215 asder8215 changed the title Refactored docs for std::fs::set_permissions_nofollow clarifying BSD-based platforms behavior Refactored docs for std::fs::set_permissions_nofollow + fix BSD-based systems to use fchmodat with AT_SYMLINK_NOFOLLOW flag Jul 29, 2026
@asder8215
asder8215 force-pushed the docs_set_perms_nofollow branch from 82ff1cb to f0403c2 Compare July 29, 2026 21:49
Comment thread library/std/src/fs/tests.rs Outdated
Comment thread library/std/src/fs/tests.rs Outdated
Comment thread library/std/src/sys/fs/unix.rs Outdated
Comment thread library/std/src/sys/fs/unix.rs Outdated
Comment thread library/std/src/fs.rs Outdated
@RalfJung

Copy link
Copy Markdown
Member

The user-facing comments are fine but this is turning into a libs discussion about the implementation.

r? libs

@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

@bors note="Multi-platform code, has been tried but known to be unreliable" rollup=iffy

@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Unknown command "note". Run @bors help or go to https://bors.rust-lang.org/help to see available commands.

@clarfonthey

Copy link
Copy Markdown
Contributor

@bors r+ note="Multi-platform code, has been tried but known to be unreliable" rollup=iffy

@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 459be4d has been approved by clarfonthey

It is now in the queue for this repository.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 25, 2026
Refactored docs for `std::fs::set_permissions_nofollow` + fix BSD-based systems to use fchmodat with AT_SYMLINK_NOFOLLOW flag



This PR refactors documentations for `std::fs::set_permissions_nofollow` and fixes BSD-based systems + Android to use `fchmodat` with `AT_SYMLINK_NOFOLLOW` flag (instead of no flag set) and refactors all other platforms to defer to `OpenOptions` with `O_NOFOLLOW` behavior.

r? @clarfonthey
Since they looked at the original `set_permissions_nofollow` PR I made

cc @RalfJung
@rust-log-analyzer

This comment has been minimized.

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 25, 2026
@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 9c04978 failed: CI. Failed job:

@clarfonthey

Copy link
Copy Markdown
Contributor

@rustbot author

Looks like Android is still not working as intended.

@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 Aug 25, 2026
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

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

@asder8215
asder8215 force-pushed the docs_set_perms_nofollow branch from 459be4d to eb1ceb9 Compare August 25, 2026 18:37
@asder8215

Copy link
Copy Markdown
Contributor Author

@bors try jobs=dist-android,arm-android

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 25, 2026
Refactored docs for `std::fs::set_permissions_nofollow` + fix BSD-based systems to use fchmodat with AT_SYMLINK_NOFOLLOW flag


try-job: dist-android
try-job: arm-android
@rust-bors

rust-bors Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 8c8e5d7 failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@asder8215

Copy link
Copy Markdown
Contributor Author

Seems like arm-linux-androideabi returned Ok(()) on a symlink using fchmodat with AT_SYMLINK_NOFOLLOW or openat with O_NOFOLLOW + fchmod. However, it didn't change the permission bits on the symlink since it's not marked as readonly, which is odd behavior.. I'm not confident in the consistency of what fchmodat returns on Android due to this issue I linked before.

@clarfonthey is it alright to just have that test not run on android?

@RalfJung

Copy link
Copy Markdown
Member

Are you sure this isn't case 1 in that issue, i.e. it ended up changing the mode of the file the symlink points to and then declared success?

@asder8215

Copy link
Copy Markdown
Contributor Author

Are you sure this isn't case 1 in that issue, i.e. it ended up changing the mode of the file the symlink points to and then declared success?

If that is the case, that seems to be an incorrect behavior produced by fchmodat with AT_SYMLINK_NOFOLLOW. I was taking a look at bionics libc fchmodat, and it seems to be calling openat with O_PATH | O_NOFOLLOW | O_CLOEXEC followed by fchmod (so fchmodat or doing the openat w/ O_NOFOLLOW + fchmod should give the same result I believe). The comment and linked thread seems to imply it was intended that fchmodat to fail on symlinks with ENOTSUP if we're not setting symlink mode?

From the bionics libc code (if that's the correct place to look at for android), I can only imagine that the openat for some reason succeeded and then fchmod changed the target permissions instead of erroring?

@RalfJung

Copy link
Copy Markdown
Member

I don't know, that's why I am asking you. ;)

The test should assert that the read-only flag on the file the symlink points to is not changed by this call.

@asder8215
asder8215 force-pushed the docs_set_perms_nofollow branch from eb1ceb9 to da31cd7 Compare August 26, 2026 06:33
…d fchmodat platform call on fchmodat and every platform falls back to open + fchmod when _res is set to ErrorKind::Unsupported; updated docs to reflect change
@asder8215
asder8215 force-pushed the docs_set_perms_nofollow branch from da31cd7 to 625be1f Compare August 26, 2026 06:36
@asder8215

Copy link
Copy Markdown
Contributor Author

I don't know, that's why I am asking you. ;)

Alright, well I adjusted the test case to check if our target file has the same permission bits before calling on set_permissions_nofollow. Let's see what happens.

@rustbot try jobs=dist-android,arm-android

Comment on lines +671 to +672
let metadata = check!(fs::metadata(&symlink_name));
let file_permission_bits = metadata.permissions();

@RalfJung RalfJung Aug 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't mix this in the middle of the other operations. The code is quite hard to follow now. Also the variable names could be more self-describing.

View changes since the review

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.