about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-08-16 06:56:11 +0000
committerbors <bors@rust-lang.org>2017-08-16 06:56:11 +0000
commit4fc3765c5477f98cfdf325475b2b01c6c094ed2d (patch)
treefd60e890abe6577dcda55e49988eda766c68f1fc /src/libstd/sys
parent6f4ab9458a7ad06c8ce630604f533c8c0c0acef4 (diff)
parent10a479ebe170398e70f872a7afa222d00a9c8f53 (diff)
downloadrust-4fc3765c5477f98cfdf325475b2b01c6c094ed2d.tar.gz
rust-4fc3765c5477f98cfdf325475b2b01c6c094ed2d.zip
Auto merge of #43883 - frewsxcv:frewsxcv-set-readonly-clarification, r=QuietMisdreavus
Clarify writable behavior of readonly-named `Permissions` methods.

Opened primarily to fix https://github.com/rust-lang/rust/issues/41984.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/fs.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index 4e6fde5c29d..cb0f687e072 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -170,11 +170,17 @@ impl AsInner<stat64> for FileAttr {
 }
 
 impl FilePermissions {
-    pub fn readonly(&self) -> bool { self.mode & 0o222 == 0 }
+    pub fn readonly(&self) -> bool {
+        // check if any class (owner, group, others) has write permission
+        self.mode & 0o222 == 0
+    }
+
     pub fn set_readonly(&mut self, readonly: bool) {
         if readonly {
+            // remove write permission for all classes; equivalent to `chmod a-w <file>`
             self.mode &= !0o222;
         } else {
+            // add write permission for all classes; equivalent to `chmod a+w <file>`
             self.mode |= 0o222;
         }
     }