Skip to content

fix typo in documentation for std::fs::Permissions #109263

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

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,11 +1406,11 @@ impl Permissions {
/// On Unix-based platforms this checks if *any* of the owner, group or others
/// write permission bits are set. It does not check if the current
/// user is in the file's assigned group. It also does not check ACLs.
/// Therefore even if this returns true you may not be able to write to the
/// file, and vice versa. The [`PermissionsExt`] trait gives direct access
/// to the permission bits but also does not read ACLs. If you need to
/// accurately know whether or not a file is writable use the `access()`
/// function from libc.
/// Therefore the return value of this function cannot be relied upon
/// to predict whether attempts to read or write the file will actually succeed.
/// The [`PermissionsExt`] trait gives direct access to the permission bits but
/// also does not read ACLs. If you need to accurately know whether or not a file
/// is writable use the `access()` function from libc.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// is writable use the `access()` function from libc.
/// is writable use the `access()` function from libc.

I think it's work mentioning that using access can lead to time-of-check-time-of-use problems where the permissions get changed between the call to access and the actual access, and therefore the return value of access also cannot be relied on for some things. The only way to figure out whether you can open a file is to open it.

Copy link
Contributor Author

@squell squell Feb 8, 2024

Choose a reason for hiding this comment

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

Perhaps the final sentence should simply be removed lest the documentation for this function turn into a tutorial about interacting with a file system.

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with removing that line.

///
/// [`PermissionsExt`]: crate::os::unix::fs::PermissionsExt
///
Expand Down