Add comments clarifying behavior of unix set_readonly behavior.

This commit is contained in:
Corey Farwell 2017-08-15 09:42:11 -04:00
parent c774c95919
commit 1949c6599d

View File

@ -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;
}
}