2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-11 15:51:02 +00:00

Merge pull request #1325 from antonlindstrom/lookup-group

Add group name in fillUser
This commit is contained in:
Alexander Neumann 2017-10-04 21:32:46 +02:00
commit 1dcfd64028

View File

@ -541,7 +541,14 @@ func (node *Node) fillUser(stat statT) error {
return err return err
} }
group, err := lookupGroup(strconv.Itoa(int(stat.gid())))
if err != nil {
return err
}
node.User = username node.User = username
node.Group = group
return nil return nil
} }
@ -573,6 +580,34 @@ func lookupUsername(uid string) (string, error) {
return username, nil 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 { func (node *Node) fillExtra(path string, fi os.FileInfo) error {
stat, ok := toStatT(fi.Sys()) stat, ok := toStatT(fi.Sys())
if !ok { if !ok {