Skip to content

Commit

Permalink
Retain suid/sgid/sticky bits in Metadata.permissions
Browse files Browse the repository at this point in the history
Most users would expect set_permissions(Metadata.permissions()) to be
non-destructive. While we can't guarantee this, we can at least pass
the needed info to chmod.

Also update the PermissionsExt documentation to disambiguate what it
contains, and to refer to the underlying value as `st_mode` rather than
its type `mode_t`.

Closes rust-lang#44147
  • Loading branch information
tmerr committed Sep 16, 2017
1 parent fd4bef5 commit e391079
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/libstd/sys/unix/ext/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl FileExt for fs::File {
/// Unix-specific extensions to `Permissions`
#[stable(feature = "fs_ext", since = "1.1.0")]
pub trait PermissionsExt {
/// Returns the underlying raw `mode_t` bits that are the standard Unix
/// permissions for this file.
/// Returns the 12 least significant bits of `st_mode` which are the
/// standard Unix permissions for this file.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub struct DirBuilder { mode: mode_t }
impl FileAttr {
pub fn size(&self) -> u64 { self.stat.st_size as u64 }
pub fn perm(&self) -> FilePermissions {
FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o777 }
FilePermissions { mode: (self.stat.st_mode as mode_t) & 0o7777 }
}

pub fn file_type(&self) -> FileType {
Expand Down

0 comments on commit e391079

Please sign in to comment.