Files
pmg/internal/doctor/doctor.go
T
Sahilb315 479f546ebc fix: actionable remedy for root-created per-user config dir
A pmg run as root with a preserved HOME (GitHub runners, sudo -E, su
without -) creates the invoking user's ~/.config/safedep as root-owned,
and event-log init then fail-closes every later non-root command.
Make that state self-solvable:

- event-log init permission errors exit with a usefulerror naming the
  likely cause and the chown fix instead of a bare fatal
- pmg setup doctor probes event-log dir writability and reports the
  same fix via a new per-result Fix override
- document the mechanism and remedy in system-install.md, along with
  the binary ownership requirements for --system
- consolidate this branch's doctor tests into doctor_test.go
2026-07-14 02:40:08 +05:30

57 lines
1.1 KiB
Go

package doctor
type CheckStatus int
const (
StatusPass CheckStatus = iota
StatusWarn
StatusFail
)
type CheckResult struct {
Name string
Category string
Status CheckStatus
Message string
ImpliesInterception bool
// Fix overrides the check's static fix hint for this specific result.
Fix string
}
type Check struct {
Name string
Category string
Run func() CheckResult
}
func RunChecks(checks []Check) []CheckResult {
results := make([]CheckResult, 0, len(checks))
for _, c := range checks {
result := c.Run()
result.Name = c.Name
result.Category = c.Category
results = append(results, result)
}
return results
}
func HasFailures(results []CheckResult) bool {
for _, r := range results {
if r.Status == StatusFail {
return true
}
}
return false
}
func CategorySummary(results []CheckResult) map[string]CheckStatus {
summary := make(map[string]CheckStatus)
for _, r := range results {
current, exists := summary[r.Category]
if !exists || r.Status > current {
summary[r.Category] = r.Status
}
}
return summary
}