Add group name in fillUser

This does a lookup of the group name from the GID and adds it to the
Node.
This commit is contained in:
Anton Lindstrom 2017-10-04 20:11:54 +02:00
parent eb59d28154
commit 26df48b2aa

View file

@ -541,7 +541,14 @@ func (node *Node) fillUser(stat statT) error {
return err
}
group, err := lookupGroup(strconv.Itoa(int(stat.gid())))
if err != nil {
return err
}
node.User = username
node.Group = group
return nil
}
@ -573,6 +580,34 @@ func lookupUsername(uid string) (string, error) {
return username, nil
}
var (
gidLookupCache = make(map[string]string)
gidLookupCacheMutex = sync.RWMutex{}
)
func lookupGroup(gid string) (string, error) {
gidLookupCacheMutex.RLock()
value, ok := gidLookupCache[gid]
gidLookupCacheMutex.RUnlock()
if ok {
return value, nil
}
group := ""
g, err := user.LookupGroupId(gid)
if err == nil {
group = g.Name
}
gidLookupCacheMutex.Lock()
gidLookupCache[gid] = group
gidLookupCacheMutex.Unlock()
return group, nil
}
func (node *Node) fillExtra(path string, fi os.FileInfo) error {
stat, ok := toStatT(fi.Sys())
if !ok {