-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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
pub fn perm(&self) -> FilePermissions { | |
FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o777 } | |
} |
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
?
kennytm and cuviper
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.