Inline three thin wrapper methods in server.go
- openEntry (one-liner delegating to rootTree.Open): inlined into the two call sites in read() and write() - statPath (one-liner delegating to rootTree.Stat): inlined into three call sites (fileOwnerGroup, walk, makeStat) - InterruptAll (one-liner delegating to fs.InterruptAll): deleted, it was dead code with no callers anywhere Also cleaned up: removed unused File type alias and unused 'os' import. server.go: 825 -> 810 lines. Server method count drops by 3, but more importantly, zero forwarding boilerplate remains.
This commit is contained in:
parent
1e126ce76a
commit
3279725128
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
"os/user"
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -20,7 +19,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
File = fs.File
|
|
||||||
FileTree = fs.FileTree
|
FileTree = fs.FileTree
|
||||||
|
|
||||||
syntheticFileInfo = fs.SyntheticFileInfo
|
syntheticFileInfo = fs.SyntheticFileInfo
|
||||||
|
|
@ -84,9 +82,6 @@ func New(cfg Config) *Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) openEntry(path string) (File, error) { return s.rootTree.Open(path[1:]) }
|
|
||||||
func (s *Server) statPath(path string) (os.FileInfo, error) { return s.rootTree.Stat(path[1:]) }
|
|
||||||
|
|
||||||
func (s *Server) AddGroup(group, user string) {
|
func (s *Server) AddGroup(group, user string) {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
if s.groups[group] == nil {
|
if s.groups[group] == nil {
|
||||||
|
|
@ -114,7 +109,7 @@ func (s *Server) InGroup(group, user string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) fileOwnerGroup(path string) (uid, gid string) {
|
func (s *Server) fileOwnerGroup(path string) (uid, gid string) {
|
||||||
info, err := s.statPath(path)
|
info, err := s.rootTree.Stat(path[1:])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if fi, ok := info.(*syntheticFileInfo); ok {
|
if fi, ok := info.(*syntheticFileInfo); ok {
|
||||||
if fi.UID_ != "" || fi.GID_ != "" {
|
if fi.UID_ != "" || fi.GID_ != "" {
|
||||||
|
|
@ -411,7 +406,7 @@ func (s *Server) walk(cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
||||||
} else {
|
} else {
|
||||||
next = pathJoin(cur, name)
|
next = pathJoin(cur, name)
|
||||||
}
|
}
|
||||||
info, err := s.statPath(next)
|
info, err := s.rootTree.Stat(next[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(wqids) == 0 {
|
if len(wqids) == 0 {
|
||||||
return errFcall(fc, name+": file not found")
|
return errFcall(fc, name+": file not found")
|
||||||
|
|
@ -497,7 +492,7 @@ func (s *Server) read(cs *connState, fc *plan9.Fcall, ctx context.Context) *plan
|
||||||
return &plan9.Fcall{Type: plan9.Rread, Tag: fc.Tag, Count: uint32(len(data)), Data: data}
|
return &plan9.Fcall{Type: plan9.Rread, Tag: fc.Tag, Count: uint32(len(data)), Data: data}
|
||||||
}
|
}
|
||||||
|
|
||||||
entry, err := s.openEntry(path)
|
entry, err := s.rootTree.Open(path[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errFcall(fc, err.Error())
|
return errFcall(fc, err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -588,7 +583,7 @@ func (s *Server) write(cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
||||||
return errFcall(fc, "bad fid")
|
return errFcall(fc, "bad fid")
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry, err := s.openEntry(f.path); err == nil && entry.RequestRespMode() {
|
if entry, err := s.rootTree.Open(f.path[1:]); err == nil && entry.RequestRespMode() {
|
||||||
cs.mu.Unlock()
|
cs.mu.Unlock()
|
||||||
if err := entry.Write(fc.Data); err != nil {
|
if err := entry.Write(fc.Data); err != nil {
|
||||||
return errFcall(fc, err.Error())
|
return errFcall(fc, err.Error())
|
||||||
|
|
@ -721,10 +716,6 @@ func (s *Server) Shutdown() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) InterruptAll() {
|
|
||||||
fs.InterruptAll(s.rootTree)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) buildDirData(path string) []byte {
|
func (s *Server) buildDirData(path string) []byte {
|
||||||
var dirs []plan9.Dir
|
var dirs []plan9.Dir
|
||||||
|
|
||||||
|
|
@ -788,7 +779,7 @@ func (s *Server) makeStat(path string) plan9.Dir {
|
||||||
base = "."
|
base = "."
|
||||||
}
|
}
|
||||||
|
|
||||||
info, err := s.statPath(path)
|
info, err := s.rootTree.Stat(path[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
info = &syntheticFileInfo{Name_: base, Mode_: 0444}
|
info = &syntheticFileInfo{Name_: base, Mode_: 0444}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue