Skip to content

Improve docs related to readonly and set readonly to improve clarity of their behaviour #101599

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

Closed
Closed
Changes from all 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
24 changes: 21 additions & 3 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,14 @@ impl FileTimes {

impl Permissions {
/// Returns `true` if these permissions describe a readonly (unwritable) file.
/// Note that readonly in this context means readonly to *all* users, and does
/// not represent that the file is readonly from the context of the calling
/// user/group.
///
/// For Unix-like systems this implies that there are no write bits set on the file.
/// This function does not consider posix-acls which may still allow write access.
///
/// For Windows this implies that the "readonly" attribute is set on the file.
///
/// # Examples
///
Expand All @@ -1390,8 +1398,17 @@ impl Permissions {
/// using the resulting `Permission` will update file permissions to allow
/// writing.
///
/// This operation does **not** modify the filesystem. To modify the
/// filesystem use the [`set_permissions`] function.
/// For Unix-like systems this modifies the write bits for owner, group and
/// everyone, and is the equivalent of chmod a+w or chmod a-w.
/// This function does not consider posix-acls which may still allow or deny
/// write access.
///
/// For Windows this alters the state of the "readonly" attribute on the file.
///
/// This operation does **not** modify the files attributes. This only
/// changes the in-memory value of these attributes for the current permissions.
/// To modify the files attributes use the [`set_permissions`] function which
/// commits these attribute changes to the file.
///
/// # Examples
///
Expand All @@ -1405,7 +1422,8 @@ impl Permissions {
///
/// permissions.set_readonly(true);
///
/// // filesystem doesn't change
/// // filesystem doesn't change, only the in memory state of the
/// // readonly permission
/// assert_eq!(false, metadata.permissions().readonly());
///
/// // just this particular `permissions`.
Expand Down