Skip to content

Commit bd160f1

Browse files
authored
Rollup merge of #130289 - intgr-forks:Permissions-readonly-vs-unix-root, r=ChrisDenton
docs: Permissions.readonly() also ignores root user special permissions The root user can write to files without any (write) permission bits set. But this is not taken into account by `std::fs::Permissions.readonly()`. The rustdoc for `readonly()` also mentions shortcomings later: > 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. But since this part already clarifies how it works -- it checks write permission bits -- I think it's not necessary to repeat the root user shortcomings here.
2 parents 303e8bd + edfdfbe commit bd160f1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: library/std/src/fs.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1869,8 +1869,10 @@ impl Permissions {
18691869
///
18701870
/// # Note
18711871
///
1872-
/// This function does not take Access Control Lists (ACLs) or Unix group
1873-
/// membership into account.
1872+
/// This function does not take Access Control Lists (ACLs), Unix group
1873+
/// membership and other nuances into account.
1874+
/// Therefore the return value of this function cannot be relied upon
1875+
/// to predict whether attempts to read or write the file will actually succeed.
18741876
///
18751877
/// # Windows
18761878
///
@@ -1885,10 +1887,13 @@ impl Permissions {
18851887
/// # Unix (including macOS)
18861888
///
18871889
/// On Unix-based platforms this checks if *any* of the owner, group or others
1888-
/// write permission bits are set. It does not check if the current
1889-
/// user is in the file's assigned group. It also does not check ACLs.
1890-
/// Therefore the return value of this function cannot be relied upon
1891-
/// to predict whether attempts to read or write the file will actually succeed.
1890+
/// write permission bits are set. It does not consider anything else, including:
1891+
///
1892+
/// * Whether the current user is in the file's assigned group.
1893+
/// * Permissions granted by ACL.
1894+
/// * That `root` user can write to files that do not have any write bits set.
1895+
/// * Writable files on a filesystem that is mounted read-only.
1896+
///
18921897
/// The [`PermissionsExt`] trait gives direct access to the permission bits but
18931898
/// also does not read ACLs.
18941899
///

0 commit comments

Comments
 (0)