File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 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 {
916916}
917917
918918impl Permissions {
919- /// Returns whether these permissions describe a readonly file.
919+ /// Returns whether these permissions describe a readonly (unwritable) file.
920920 ///
921921 /// # Examples
922922 ///
@@ -934,7 +934,11 @@ impl Permissions {
934934 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
935935 pub fn readonly ( & self ) -> bool { self . 0 . readonly ( ) }
936936
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.
938942 ///
939943 /// This operation does **not** modify the filesystem. To modify the
940944 /// 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 {
170170}
171171
172172impl 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 }
You can’t perform that action at this time.
0 commit comments