2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 00:33:57 +00:00

Remove unused error return in lookup{Username,Group}

This commit is contained in:
greatroar 2020-10-12 14:40:54 +02:00
parent 0ae02f3030
commit a03fe4562e

View File

@ -506,24 +506,12 @@ func (node Node) sameExtendedAttributes(other Node) bool {
return true return true
} }
func (node *Node) fillUser(stat statT) error { func (node *Node) fillUser(stat statT) {
node.UID = stat.uid() uid, gid := stat.uid(), stat.gid()
node.GID = stat.gid() node.UID, node.GID = uid, gid
username, err := lookupUsername(strconv.Itoa(int(stat.uid()))) node.User = lookupUsername(strconv.Itoa(int(uid)))
if err != nil { node.Group = lookupGroup(strconv.Itoa(int(gid)))
return err
}
group, err := lookupGroup(strconv.Itoa(int(stat.gid())))
if err != nil {
return err
}
node.User = username
node.Group = group
return nil
} }
var ( var (
@ -531,13 +519,14 @@ var (
uidLookupCacheMutex = sync.RWMutex{} uidLookupCacheMutex = sync.RWMutex{}
) )
func lookupUsername(uid string) (string, error) { // Cached user name lookup by uid. Returns "" when no name can be found.
func lookupUsername(uid string) string {
uidLookupCacheMutex.RLock() uidLookupCacheMutex.RLock()
value, ok := uidLookupCache[uid] value, ok := uidLookupCache[uid]
uidLookupCacheMutex.RUnlock() uidLookupCacheMutex.RUnlock()
if ok { if ok {
return value, nil return value
} }
username := "" username := ""
@ -551,7 +540,7 @@ func lookupUsername(uid string) (string, error) {
uidLookupCache[uid] = username uidLookupCache[uid] = username
uidLookupCacheMutex.Unlock() uidLookupCacheMutex.Unlock()
return username, nil return username
} }
var ( var (
@ -559,13 +548,14 @@ var (
gidLookupCacheMutex = sync.RWMutex{} gidLookupCacheMutex = sync.RWMutex{}
) )
func lookupGroup(gid string) (string, error) { // Cached group name lookup by gid. Returns "" when no name can be found.
func lookupGroup(gid string) string {
gidLookupCacheMutex.RLock() gidLookupCacheMutex.RLock()
value, ok := gidLookupCache[gid] value, ok := gidLookupCache[gid]
gidLookupCacheMutex.RUnlock() gidLookupCacheMutex.RUnlock()
if ok { if ok {
return value, nil return value
} }
group := "" group := ""
@ -579,7 +569,7 @@ func lookupGroup(gid string) (string, error) {
gidLookupCache[gid] = group gidLookupCache[gid] = group
gidLookupCacheMutex.Unlock() gidLookupCacheMutex.Unlock()
return group, nil return group
} }
func (node *Node) fillExtra(path string, fi os.FileInfo) error { func (node *Node) fillExtra(path string, fi os.FileInfo) error {
@ -597,11 +587,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
node.fillTimes(stat) node.fillTimes(stat)
var err error node.fillUser(stat)
if err = node.fillUser(stat); err != nil {
return err
}
switch node.Type { switch node.Type {
case "file": case "file":
@ -609,6 +595,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
node.Links = uint64(stat.nlink()) node.Links = uint64(stat.nlink())
case "dir": case "dir":
case "symlink": case "symlink":
var err error
node.LinkTarget, err = fs.Readlink(path) node.LinkTarget, err = fs.Readlink(path)
node.Links = uint64(stat.nlink()) node.Links = uint64(stat.nlink())
if err != nil { if err != nil {
@ -626,7 +613,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
return errors.Errorf("invalid node type %q", node.Type) return errors.Errorf("invalid node type %q", node.Type)
} }
if err = node.fillExtendedAttributes(path); err != nil { if err := node.fillExtendedAttributes(path); err != nil {
return err return err
} }