about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Merrifield <trevorm42@gmail.com>2017-09-11 20:02:44 -0400
committerTrevor Merrifield <trevorm42@gmail.com>2017-09-15 22:42:34 -0400
commite3910794961b820defedd909b11e69681803e0db (patch)
tree2fee8090d462e10f638905874074a730fb053e7e
parentfd4bef54abafe6d93ec3c87498de696da6ef5819 (diff)
downloadrust-e3910794961b820defedd909b11e69681803e0db.tar.gz
rust-e3910794961b820defedd909b11e69681803e0db.zip
Retain suid/sgid/sticky bits in Metadata.permissions
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 #44147
-rw-r--r--src/libstd/sys/unix/ext/fs.rs4
-rw-r--r--src/libstd/sys/unix/fs.rs2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs
index f44b9aa9615..96c0f4eab42 100644
--- a/src/libstd/sys/unix/ext/fs.rs
+++ b/src/libstd/sys/unix/ext/fs.rs
@@ -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
     ///
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index 13112fc1fa5..e0ce02873f5 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -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 {