Commit bd6adb6
fix(store): mkdir cost-DB parent dir on OpenCostStore
mattn/go-sqlite3 surfaces a missing parent dir as the unhelpful
"unable to open database file: no such file or directory" error.
Production opens ctm.db at ~/.config/ctm/ctm.db — on a fresh install
or a CI runner with no pre-existing config dir, the parent doesn't
exist and OpenCostStore fails before doing anything useful.
Add a defensive os.MkdirAll(filepath.Dir(path), 0o700) at the top of
OpenCostStore. Skipped for the in-memory path (":memory:" → Dir
returns "." which is a no-op anyway, but explicit guard reads
better). Mkdir errors are swallowed — if mkdir fails we let
sql.Open surface the real problem instead of masking it.
Side benefit: server_test.go's TestHealthz* / TestAuth* etc. were
flakily passing or failing depending on whether earlier-running
test packages (alphabetical: internal/config, …) created
~/.config/ctm/ as a side effect. CI runs without a populated test
cache hit this regularly. Now they're independent.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 5e54a32 commit bd6adb6
1 file changed
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
| |||
0 commit comments