File tree 2 files changed +13
-3
lines changed
2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -916,7 +916,7 @@ impl AsInner<fs_imp::FileAttr> for Metadata {
916
916
}
917
917
918
918
impl Permissions {
919
- /// Returns whether these permissions describe a readonly file.
919
+ /// Returns whether these permissions describe a readonly (unwritable) file.
920
920
///
921
921
/// # Examples
922
922
///
@@ -934,7 +934,11 @@ impl Permissions {
934
934
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
935
935
pub fn readonly ( & self ) -> bool { self . 0 . readonly ( ) }
936
936
937
- /// Modifies the readonly flag for this set of permissions.
937
+ /// Modifies the readonly flag for this set of permissions. If the
938
+ /// `readonly` argument is `true`, using the resulting `Permission` will
939
+ /// update file permissions to forbid writing. Conversely, if it's `false`,
940
+ /// using the resulting `Permission` will update file permissions to allow
941
+ /// writing.
938
942
///
939
943
/// This operation does **not** modify the filesystem. To modify the
940
944
/// filesystem use the `fs::set_permissions` function.
Original file line number Diff line number Diff line change @@ -170,11 +170,17 @@ impl AsInner<stat64> for FileAttr {
170
170
}
171
171
172
172
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
+
174
178
pub fn set_readonly ( & mut self , readonly : bool ) {
175
179
if readonly {
180
+ // remove write permission for all classes; equivalent to `chmod a-w <file>`
176
181
self . mode &= !0o222 ;
177
182
} else {
183
+ // add write permission for all classes; equivalent to `chmod a+w <file>`
178
184
self . mode |= 0o222 ;
179
185
}
180
186
}
You can’t perform that action at this time.
0 commit comments