makeStat: delegate file modes to backing tree

Remove hardcoded permission switch in makeStat and delegate to
the underlying FileTree.Stat() instead. This makes FileList in
sessionfile.go the single source of truth for session file modes.
This commit is contained in:
Levi Neely 2026-05-20 10:42:29 +02:00
parent fe6e2c04a8
commit baa7ca66e6
2 changed files with 9 additions and 43 deletions

View File

@ -1018,49 +1018,15 @@ func (s *Server) makeStat(path string) plan9.Dir {
mode = plan9.DMDIR | 0755
}
} else {
switch base {
case "ctl":
mode = 0222 // owner+group+other write
case "prompt", "fifo.in":
mode = 0022 // group+other write; owner cannot write (no self-prompt)
case "chat", "usage", "cost", "ctxsz", "models", "fifo.out", "offset", "statewait", "systemprompt":
mode = 0444
case "cfg":
mode = 0666
case "tail":
mode = 0555
default:
if path == "/backends" || path == "/help" {
mode = 0444
} else if isSessionFile(path) {
mode_, _ := session.FileMode(base)
mode = plan9.Perm(mode_)
} else if strings.HasPrefix(path, "/a/") {
mode = 0666
} else if strings.HasPrefix(path, "/p/") {
mode = 0664
} else if strings.HasPrefix(path, "/m/") {
mode = 0666
} else if path == "/sk/idx" {
mode = 0444
} else if strings.HasPrefix(path, "/sk/") {
mode = 0664
} else if strings.HasPrefix(path, "/s/") {
parts := strings.SplitN(strings.TrimPrefix(path, "/s/"), "/", 3)
if len(parts) == 3 && parts[1] == "t" && parts[2] == "idx" {
mode = 0400
} else if len(parts) == 3 && parts[1] == "t" {
mode = 0500
} else {
mode = 0444
}
} else if strings.HasPrefix(path, "/u/") {
mode = 0555
} else if strings.HasPrefix(path, "/x/") {
mode = 0555
// Delegate to the backing tree for file mode.
if tree, name := s.route(path); tree != nil {
if info, err := tree.Stat(name); err == nil {
mode = plan9.Perm(info.Mode())
} else {
mode = 0444
}
} else {
mode = 0444
}
}

View File

@ -23,10 +23,10 @@ var FileList = []struct {
}{
{"plan", 0666, false, false},
{"ctl", 0200, false, true},
{"prompt", 0200, false, true},
{"fifo.in", 0200, false, true},
{"prompt", 0466, false, true},
{"fifo.in", 0222, false, true},
{"fifo.out", 0444, true, false},
{"chat", 0666, false, false},
{"chat", 0444, false, false},
{"offset", 0444, false, false},
{"cfg", 0666, false, false},
{"state", 0444, false, false},