Closed
Description
Behavior
On linux, mkdir mydir
, chmod 2777 mydir
then run:
fn main() {
let path = "mydir";
let perms = std::fs::metadata(path).unwrap().permissions();
std::fs::set_permissions(path, perms).unwrap();
}
This changes the permissions of mydir
to 777
. Is this expected?
The cause
Metadata.permissions()
masks away everything other than the lower 3 triads when it calls out to this code:
rust/src/libstd/sys/unix/fs.rs
Lines 95 to 97 in d2d5069
Then std::fs::set_permissions
sends these mode bits into into chmod which considers four triads, not three. Possibly useful references: chmod and mode_t
Should we change Metadata.permissions to preserve that triad, maybe by masking with 0o7777
instead of 0o777
?