func (u *vUser) IsMember(g p.Group) bool { // The Id is the immutable fact for the user. // It is what is stored as uid,gid on files. // It happens to be int in the go9p implementation // (as opposed to string in Plan9), but this has the // advantage of using compiler to ensure that we can't // check an Id() against a Name(). for _, b := range u.groups { if b.Id() == g.Id() { return true } } return false }
// Initializes the fields of a file and add it to a directory. // Returns nil if successful, or an error. func (f *File) Add(dir *File, name string, uid p.User, gid p.Group, mode uint32, ops interface{}) error { lock.Lock() qpath := qnext qnext++ lock.Unlock() f.Qid.Type = uint8(mode >> 24) f.Qid.Version = 0 f.Qid.Path = qpath f.Mode = mode f.Atime = uint32(time.Now().Unix()) f.Mtime = f.Atime f.Length = 0 f.Name = name if uid != nil { f.Uid = uid.Name() f.Uidnum = uint32(uid.Id()) } else { f.Uid = "none" f.Uidnum = p.NOUID } if gid != nil { f.Gid = gid.Name() f.Gidnum = uint32(gid.Id()) } else { f.Gid = "none" f.Gidnum = p.NOUID } f.Muid = "" f.Muidnum = p.NOUID f.Ext = "" if dir != nil { f.Parent = dir dir.Lock() for p := dir.cfirst; p != nil; p = p.next { if name == p.Name { dir.Unlock() return Eexist } } if dir.clast != nil { dir.clast.next = f } else { dir.cfirst = f } f.prev = dir.clast f.next = nil dir.clast = f dir.Unlock() } else { f.Parent = f } f.Ops = ops return nil }