about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-09-22 10:30:20 +0000
committerbors <bors@rust-lang.org>2017-09-22 10:30:20 +0000
commitee409a489eebab8a28078bb04c29d13442b74ee5 (patch)
tree6734aba814ec62e77a01e904b922efdc3971b12d /src
parent0962b8fe4ffc1face685bc1b04364f6a3f0ad1ea (diff)
parent6ae9fc277287e4f207012ab65be24058f143d42d (diff)
downloadrust-ee409a489eebab8a28078bb04c29d13442b74ee5.tar.gz
rust-ee409a489eebab8a28078bb04c29d13442b74ee5.zip
Auto merge of #44624 - tmerr:master, r=sfackler
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
Diffstat (limited to 'src')
-rw-r--r--src/libstd/fs.rs21
-rw-r--r--src/libstd/sys/unix/ext/fs.rs4
-rw-r--r--src/libstd/sys/unix/fs.rs2
3 files changed, 24 insertions, 3 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 2a916b819cc..99162766081 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -2161,6 +2161,27 @@ mod tests {
     }
 
     #[test]
+    #[cfg(unix)]
+    fn set_get_unix_permissions() {
+        use os::unix::fs::PermissionsExt;
+
+        let tmpdir = tmpdir();
+        let filename = &tmpdir.join("set_get_unix_permissions");
+        check!(fs::create_dir(filename));
+        let mask = 0o7777;
+
+        check!(fs::set_permissions(filename,
+                                   fs::Permissions::from_mode(0)));
+        let metadata0 = check!(fs::metadata(filename));
+        assert_eq!(mask & metadata0.permissions().mode(), 0);
+
+        check!(fs::set_permissions(filename,
+                                   fs::Permissions::from_mode(0o1777)));
+        let metadata1 = check!(fs::metadata(filename));
+        assert_eq!(mask & metadata1.permissions().mode(), 0o1777);
+    }
+
+    #[test]
     #[cfg(windows)]
     fn file_test_io_seek_read_write() {
         use os::windows::fs::FileExt;
diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs
index f44b9aa9615..3e631ad40ac 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 underlying raw `st_mode` bits that contain 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..c4616c3b395 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) }
     }
 
     pub fn file_type(&self) -> FileType {