lib/fs: Cache user lookups (#8496)

This commit is contained in:
Jakob Borg
2022-08-12 07:48:00 +02:00
committed by GitHub
parent 06273875ae
commit eb81f7400c
7 changed files with 85 additions and 16 deletions
+2 -5
View File
@@ -8,7 +8,6 @@ package fs
import (
"fmt"
"os/user"
"github.com/syncthing/syncthing/lib/protocol"
"golang.org/x/sys/windows"
@@ -35,12 +34,10 @@ func (f *BasicFilesystem) PlatformData(name string) (protocol.PlatformData, erro
return protocol.PlatformData{}, fmt.Errorf("get owner for %s: %w", rootedName, err)
}
// The owner SID might represent a user or a group. We try to look it up
// as both, and set the appropriate fields in the OS data.
pd := &protocol.WindowsData{}
if us, err := user.LookupId(owner.String()); err == nil {
if us := f.userCache.lookup(owner.String()); us != nil {
pd.OwnerName = us.Username
} else if gr, err := user.LookupGroupId(owner.String()); err == nil {
} else if gr := f.groupCache.lookup(owner.String()); gr != nil {
pd.OwnerName = gr.Name
pd.OwnerIsGroup = true
} else {