Skip to content

Documentation for PermissionsExt::set_mode should link to set_permissions #91707

Closed
@0xpr03

Description

@0xpr03

I'm opening this issue because it took me far too much time to realize that set_mode isn't actually doing anything to the underlying file.
Based on the rust std docs I've first tried to set an executable bit with this code:

let file = std::fs::File::open(path)?;
let metadata = file.metadata()?;
let mut permissions = metadata.permissions();
permissions.set_mode(0o700);

I expected to see this happen: The code sets the permissions bit.

Instead, this happened: Obviously nothing, because you have to call std::fs::set_permissions

The docs for PermissionsExt::set_mode should link to std::fs::set_permissions so users know that set_mode doesn't actually perform anything on the file and instead something like this should be done:

fs::set_permissions(path, PermissionsExt::from_mode(0o700))?;

This may be relevant for more than only std::os::unix::fs::PermissionsExt.

Meta

rustc --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions