We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
set_readonly
1 parent c774c95 commit 1949c65Copy full SHA for 1949c65
src/libstd/sys/unix/fs.rs
@@ -170,11 +170,17 @@ impl AsInner<stat64> for FileAttr {
170
}
171
172
impl FilePermissions {
173
- pub fn readonly(&self) -> bool { self.mode & 0o222 == 0 }
+ pub fn readonly(&self) -> bool {
174
+ // check if any class (owner, group, others) has write permission
175
+ self.mode & 0o222 == 0
176
+ }
177
+
178
pub fn set_readonly(&mut self, readonly: bool) {
179
if readonly {
180
+ // remove write permission for all classes; equivalent to `chmod a-w <file>`
181
self.mode &= !0o222;
182
} else {
183
+ // add write permission for all classes; equivalent to `chmod a+w <file>`
184
self.mode |= 0o222;
185
186
0 commit comments