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:
parent
eb59d28154
commit
26df48b2aa
1 changed files with 35 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue