Skip to content

Commit 1949c65

Browse files
committed
Add comments clarifying behavior of unix set_readonly behavior.
1 parent c774c95 commit 1949c65

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libstd/sys/unix/fs.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,17 @@ impl AsInner<stat64> for FileAttr {
170170
}
171171

172172
impl FilePermissions {
173-
pub fn readonly(&self) -> bool { self.mode & 0o222 == 0 }
173+
pub fn readonly(&self) -> bool {
174+
// check if any class (owner, group, others) has write permission
175+
self.mode & 0o222 == 0
176+
}
177+
174178
pub fn set_readonly(&mut self, readonly: bool) {
175179
if readonly {
180+
// remove write permission for all classes; equivalent to `chmod a-w <file>`
176181
self.mode &= !0o222;
177182
} else {
183+
// add write permission for all classes; equivalent to `chmod a+w <file>`
178184
self.mode |= 0o222;
179185
}
180186
}

0 commit comments

Comments
 (0)