瀏覽代碼

Fix bug about nonexistent groups in groups column

Ben S 11 年之前
父節點
當前提交
68cd6d5da1
共有 1 個文件被更改,包括 5 次插入2 次删除
  1. 5 2
      unix.rs

+ 5 - 2
unix.rs

@@ -73,8 +73,11 @@ impl Unix {
         }
         }
     }
     }
 
 
-    pub fn is_group_member(&self, gid: u32) -> bool {
-        *self.groups.get(&gid)
+    pub fn is_group_member(&mut self, gid: u32) -> bool {
+        // Groups that no longer exist have no members. If this method
+        // is called before a group with the given gid has been read,
+        // it doesn't exist, so insert false.
+        *self.groups.find_or_insert(gid, false)
     }
     }
 
 
     pub fn get_user_name(&mut self, uid: u32) -> Option<String> {
     pub fn get_user_name(&mut self, uid: u32) -> Option<String> {