From 1949c6599d7d088eca6893f1c118b05e5c5d1679 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 15 Aug 2017 09:42:11 -0400 Subject: Add comments clarifying behavior of unix `set_readonly` behavior. --- src/libstd/sys/unix/fs.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/libstd/sys') 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 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 ` self.mode &= !0o222; } else { + // add write permission for all classes; equivalent to `chmod a+w ` self.mode |= 0o222; } } -- cgit 1.4.1-3-g733a5