Closed
Description
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