|
1 | 1 | package doctor |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "fmt" |
5 | 6 | "os" |
6 | 7 | "path/filepath" |
@@ -35,31 +36,52 @@ func NewStaleSQLServerInfoCheck() *StaleSQLServerInfoCheck { |
35 | 36 | func (c *StaleSQLServerInfoCheck) Run(ctx *CheckContext) *CheckResult { |
36 | 37 | c.staleFiles = nil |
37 | 38 |
|
38 | | - // Find all sql-server.info files under the town root |
| 39 | + // Find sql-server.info files in known .beads/dolt/.dolt/ locations. |
| 40 | + // Avoids filepath.Walk over the entire town root, which is extremely slow |
| 41 | + // on Docker bind mounts (macOS VirtioFS). |
39 | 42 | var details []string |
40 | | - _ = filepath.Walk(ctx.TownRoot, func(path string, info os.FileInfo, err error) error { |
41 | | - if err != nil { |
42 | | - return nil |
43 | | - } |
44 | | - // Skip .git directories and node_modules |
45 | | - if info.IsDir() && (info.Name() == ".git" || info.Name() == "node_modules") { |
46 | | - return filepath.SkipDir |
| 43 | + |
| 44 | + locations := []string{ |
| 45 | + filepath.Join(ctx.TownRoot, ".beads", "dolt", ".dolt", "sql-server.info"), |
| 46 | + } |
| 47 | + |
| 48 | + // Collect rig names from rigs.json and top-level directories. |
| 49 | + rigNames := make(map[string]struct{}) |
| 50 | + rigsConfig := filepath.Join(ctx.TownRoot, "mayor", "rigs.json") |
| 51 | + if data, err := os.ReadFile(rigsConfig); err == nil { |
| 52 | + var rigs struct { |
| 53 | + Rigs map[string]struct{} `json:"rigs"` |
47 | 54 | } |
48 | | - if info.Name() != "sql-server.info" { |
49 | | - return nil |
| 55 | + if json.Unmarshal(data, &rigs) == nil { |
| 56 | + for name := range rigs.Rigs { |
| 57 | + rigNames[name] = struct{}{} |
| 58 | + } |
50 | 59 | } |
51 | | - // Only care about files inside .dolt directories |
52 | | - if !strings.Contains(path, ".dolt") { |
53 | | - return nil |
| 60 | + } |
| 61 | + // Also scan top-level directories as fallback (handles rigs not yet in rigs.json). |
| 62 | + if entries, err := os.ReadDir(ctx.TownRoot); err == nil { |
| 63 | + for _, e := range entries { |
| 64 | + if e.IsDir() && !strings.HasPrefix(e.Name(), ".") { |
| 65 | + rigNames[e.Name()] = struct{}{} |
| 66 | + } |
54 | 67 | } |
| 68 | + } |
| 69 | + for rigName := range rigNames { |
| 70 | + locations = append(locations, |
| 71 | + filepath.Join(ctx.TownRoot, rigName, ".beads", "dolt", ".dolt", "sql-server.info"), |
| 72 | + ) |
| 73 | + } |
55 | 74 |
|
| 75 | + for _, path := range locations { |
| 76 | + if _, err := os.Stat(path); err != nil { |
| 77 | + continue |
| 78 | + } |
56 | 79 | if c.isStale(path) { |
57 | 80 | c.staleFiles = append(c.staleFiles, path) |
58 | 81 | relPath, _ := filepath.Rel(ctx.TownRoot, path) |
59 | 82 | details = append(details, fmt.Sprintf("Stale sql-server.info: %s", relPath)) |
60 | 83 | } |
61 | | - return nil |
62 | | - }) |
| 84 | + } |
63 | 85 |
|
64 | 86 | if len(c.staleFiles) == 0 { |
65 | 87 | return &CheckResult{ |
|
0 commit comments