cleanup: remove dead code from olliesrv
- Remove unused GroupTable.Remove() method, rename Add to Populate
- Remove unused toolPrompt field from Server struct and Config
- Remove unused ModelCache type alias
- Remove unused toolsrv import
- Flatten if true {} blocks (debugging remnants)
- Convert fcallTypeName switch to map lookup
- Remove unused Tree.Unmount() method
-44 lines
This commit is contained in:
parent
0c6dd5b32a
commit
66850e822f
|
|
@ -20,11 +20,10 @@ import (
|
|||
"ollie/fs"
|
||||
olog "ollie/log"
|
||||
"ollie/mount"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
"ollie/paths"
|
||||
"ollie/skills"
|
||||
"ollie/toolsrv"
|
||||
|
||||
"github.com/godbus/dbus/v5"
|
||||
)
|
||||
|
||||
const serviceName = "ollie"
|
||||
|
|
@ -32,10 +31,6 @@ const serviceName = "ollie"
|
|||
var tcpAddr = flag.String("tcp", "", "also listen on TCP address (e.g. :564)")
|
||||
var yolo = flag.Bool("yolo", false, "skip landrun sandbox for shell")
|
||||
|
||||
// ModelCache is a type alias for the fs.ModelCache used by root-level handlers.
|
||||
// The server can use it for prefetching.
|
||||
type ModelCache = fs.ModelCache
|
||||
|
||||
func main() {
|
||||
flag.CommandLine.Parse(os.Args[1:]) //nolint:errcheck
|
||||
|
||||
|
|
@ -90,15 +85,13 @@ func runServer(sockPath string) {
|
|||
env.EnsureDefaults()
|
||||
|
||||
// Remove stale sockets from this and prior runs
|
||||
if true {
|
||||
if _, err := os.Stat(sockPath); err == nil {
|
||||
os.Remove(sockPath) //nolint:errcheck
|
||||
}
|
||||
sockDir := filepath.Dir(sockPath)
|
||||
if entries, err := filepath.Glob(filepath.Join(sockDir, "toolsrv-*.sock")); err == nil {
|
||||
for _, s := range entries {
|
||||
os.Remove(s) //nolint:errcheck
|
||||
}
|
||||
if _, err := os.Stat(sockPath); err == nil {
|
||||
os.Remove(sockPath) //nolint:errcheck
|
||||
}
|
||||
sockDir := filepath.Dir(sockPath)
|
||||
if entries, err := filepath.Glob(filepath.Join(sockDir, "toolsrv-*.sock")); err == nil {
|
||||
for _, s := range entries {
|
||||
os.Remove(s) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,42 +181,36 @@ func runServer(sockPath string) {
|
|||
}
|
||||
|
||||
// Create 9P server (after broker is ready so it can be passed in)
|
||||
if true {
|
||||
srv = New(Config{
|
||||
Sink: sink,
|
||||
RootTree: rootTree,
|
||||
ToolPrompt: toolsrv.ToolPrompt,
|
||||
})
|
||||
}
|
||||
srv = New(Config{
|
||||
Sink: sink,
|
||||
RootTree: rootTree,
|
||||
})
|
||||
|
||||
// Prefetch models asynchronously at startup
|
||||
go modelCache.Get()
|
||||
|
||||
var listener net.Listener
|
||||
if true {
|
||||
var err error
|
||||
listener, err = net.Listen("unix", sockPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "listen: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go srv.Start(conn)
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Printf("olliesrv listening on %s\n", sockPath)
|
||||
var err error
|
||||
listener, err = net.Listen("unix", sockPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "listen: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
go func() {
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go srv.Start(conn)
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Printf("olliesrv listening on %s\n", sockPath)
|
||||
|
||||
var tcpListener net.Listener
|
||||
if true && *tcpAddr != "" {
|
||||
var err error
|
||||
if *tcpAddr != "" {
|
||||
tcpListener, err = net.Listen("tcp", *tcpAddr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "tcp listen: %v\n", err)
|
||||
|
|
@ -259,8 +246,6 @@ func runServer(sockPath string) {
|
|||
if srv != nil {
|
||||
srv.Kill()
|
||||
}
|
||||
if true {
|
||||
os.Remove(sockPath)
|
||||
}
|
||||
os.Remove(sockPath)
|
||||
sink.Flush()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func NewGroupTable() *GroupTable {
|
|||
return &GroupTable{groups: make(map[string]map[string]bool)}
|
||||
}
|
||||
|
||||
func (g *GroupTable) Add(group, user string) {
|
||||
func (g *GroupTable) Populate(group, user string) {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
if g.groups[group] == nil {
|
||||
|
|
@ -47,17 +47,6 @@ func (g *GroupTable) Add(group, user string) {
|
|||
g.groups[group][user] = true
|
||||
}
|
||||
|
||||
func (g *GroupTable) Remove(group, user string) {
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
if m := g.groups[group]; m != nil {
|
||||
delete(m, user)
|
||||
if len(m) == 0 {
|
||||
delete(g.groups, group)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupTable) IsMember(group, user string) bool {
|
||||
g.mu.RLock()
|
||||
defer g.mu.RUnlock()
|
||||
|
|
@ -90,7 +79,6 @@ type Server struct {
|
|||
sink *olog.Sink
|
||||
rootTree *fs.Tree
|
||||
groups *GroupTable
|
||||
toolPrompt func(string) string
|
||||
serveWG sync.WaitGroup
|
||||
shutdownCtx context.Context
|
||||
shutdownCancel context.CancelFunc
|
||||
|
|
@ -100,9 +88,8 @@ type Server struct {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
Sink *olog.Sink
|
||||
RootTree *fs.Tree
|
||||
ToolPrompt func(string) string
|
||||
Sink *olog.Sink
|
||||
RootTree *fs.Tree
|
||||
}
|
||||
|
||||
func New(cfg Config) *Server {
|
||||
|
|
@ -112,7 +99,6 @@ func New(cfg Config) *Server {
|
|||
sink: cfg.Sink,
|
||||
rootTree: cfg.RootTree,
|
||||
groups: NewGroupTable(),
|
||||
toolPrompt: cfg.ToolPrompt,
|
||||
shutdownCtx: ctx,
|
||||
shutdownCancel: cancel,
|
||||
activeConns: make(map[net.Conn]struct{}),
|
||||
|
|
@ -263,37 +249,27 @@ func flush(cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
|||
return &plan9.Fcall{Type: plan9.Rflush, Tag: fc.Tag}
|
||||
}
|
||||
|
||||
var fcallTypeNames = map[uint8]string{
|
||||
plan9.Tversion: "Tversion",
|
||||
plan9.Tauth: "Tauth",
|
||||
plan9.Tattach: "Tattach",
|
||||
plan9.Twalk: "Twalk",
|
||||
plan9.Topen: "Topen",
|
||||
plan9.Tcreate: "Tcreate",
|
||||
plan9.Tread: "Tread",
|
||||
plan9.Twrite: "Twrite",
|
||||
plan9.Tstat: "Tstat",
|
||||
plan9.Twstat: "Twstat",
|
||||
plan9.Tflush: "Tflush",
|
||||
plan9.Tclunk: "Tclunk",
|
||||
plan9.Tremove: "Tremove",
|
||||
}
|
||||
|
||||
func fcallTypeName(t uint8) string {
|
||||
switch t {
|
||||
case plan9.Tversion:
|
||||
return "Tversion"
|
||||
case plan9.Tauth:
|
||||
return "Tauth"
|
||||
case plan9.Tattach:
|
||||
return "Tattach"
|
||||
case plan9.Twalk:
|
||||
return "Twalk"
|
||||
case plan9.Topen:
|
||||
return "Topen"
|
||||
case plan9.Tcreate:
|
||||
return "Tcreate"
|
||||
case plan9.Tread:
|
||||
return "Tread"
|
||||
case plan9.Twrite:
|
||||
return "Twrite"
|
||||
case plan9.Tstat:
|
||||
return "Tstat"
|
||||
case plan9.Twstat:
|
||||
return "Twstat"
|
||||
case plan9.Tflush:
|
||||
return "Tflush"
|
||||
case plan9.Tclunk:
|
||||
return "Tclunk"
|
||||
case plan9.Tremove:
|
||||
return "Tremove"
|
||||
default:
|
||||
return fmt.Sprintf("T%d", t)
|
||||
if name, ok := fcallTypeNames[t]; ok {
|
||||
return name
|
||||
}
|
||||
return fmt.Sprintf("T%d", t)
|
||||
}
|
||||
|
||||
func errFcall(fc *plan9.Fcall, msg string) *plan9.Fcall {
|
||||
|
|
@ -345,7 +321,7 @@ func attach(groups *GroupTable, cs *connState, fc *plan9.Fcall) *plan9.Fcall {
|
|||
qid := plan9.Qid{Type: QTDir, Path: 0}
|
||||
cs.fids[fc.Fid] = &fid{path: "/", qid: qid}
|
||||
if fc.Uname != "" {
|
||||
groups.Add("agent", fc.Uname)
|
||||
groups.Populate("agent", fc.Uname)
|
||||
}
|
||||
return &plan9.Fcall{Type: plan9.Rattach, Tag: fc.Tag, Qid: qid}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,11 +98,6 @@ func (d *Tree) Mount(name string, child *Tree) {
|
|||
d.children[name] = child
|
||||
}
|
||||
|
||||
// Unmount removes a mounted child.
|
||||
func (d *Tree) Unmount(name string) {
|
||||
delete(d.children, name)
|
||||
}
|
||||
|
||||
// Child returns the child mounted at name, or nil.
|
||||
func (d *Tree) Child(name string) *Tree {
|
||||
if d.children == nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue