WriteLatest writes an artifact atomically to .codemap/handoff.latest.json.
(root string, artifact *Artifact)
| 74 | |
| 75 | // WriteLatest writes an artifact atomically to .codemap/handoff.latest.json. |
| 76 | func WriteLatest(root string, artifact *Artifact) error { |
| 77 | normalizeArtifact(artifact) |
| 78 | |
| 79 | path := LatestPath(root) |
| 80 | if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { |
| 81 | return err |
| 82 | } |
| 83 | |
| 84 | if err := writeJSONAtomic(path, artifact); err != nil { |
| 85 | return err |
| 86 | } |
| 87 | if err := writeJSONAtomic(PrefixPath(root), artifact.Prefix); err != nil { |
| 88 | return err |
| 89 | } |
| 90 | if err := writeJSONAtomic(DeltaPath(root), artifact.Delta); err != nil { |
| 91 | return err |
| 92 | } |
| 93 | return appendMetrics(root, artifact) |
| 94 | } |
| 95 | |
| 96 | func writeJSONAtomic(path string, value any) error { |
| 97 | data, err := json.MarshalIndent(value, "", " ") |