fileOwnerGroup: convert from method to package-level function

fileOwnerGroup only needed s.rootTree, not the full *Server. Making
it a function taking (*fs.Tree, string) removes one more method from
Server, makes the dependency explicit, and makes it unit-testable.
This commit is contained in:
Ollie Agent 2026-08-02 15:31:33 +02:00
parent 3279725128
commit 082ba1c511
1 changed files with 4 additions and 4 deletions

View File

@ -108,8 +108,8 @@ func (s *Server) InGroup(group, user string) bool {
return s.groups[group][user]
}
func (s *Server) fileOwnerGroup(path string) (uid, gid string) {
info, err := s.rootTree.Stat(path[1:])
func fileOwnerGroup(root *fs.Tree, path string) (uid, gid string) {
info, err := root.Stat(path[1:])
if err == nil {
if fi, ok := info.(*syntheticFileInfo); ok {
if fi.UID_ != "" || fi.GID_ != "" {
@ -124,7 +124,7 @@ func (s *Server) fileOwnerGroup(path string) (uid, gid string) {
}
func (s *Server) checkPerm(uname, path string, mode uint8) error {
uid, gid := s.fileOwnerGroup(path)
uid, gid := fileOwnerGroup(s.rootTree, path)
dir := s.makeStat(path)
perm := uint32(dir.Mode) & 0777
var bits uint32
@ -790,7 +790,7 @@ func (s *Server) makeStat(path string) plan9.Dir {
qid.Type = QTDir
}
uid, gid := s.fileOwnerGroup(path)
uid, gid := fileOwnerGroup(s.rootTree, path)
dir := plan9.Dir{
Qid: qid,
Mode: plan9.Perm(info.Mode()),