Skip to content

Commit

Permalink
Add comments clarifying behavior of unix set_readonly behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Aug 15, 2017
1 parent c774c95 commit 1949c65
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libstd/sys/unix/fs.rs
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 1949c65

Please sign in to comment.