MCPcopy Create free account
hub / github.com/JordanCoin/codemap / capMetricsLog

Function capMetricsLog

handoff/storage.go:222–252  ·  view source on GitHub ↗
(root string, maxLines int)

Source from the content-addressed store, hash-verified

220}
221
222func capMetricsLog(root string, maxLines int) error {
223 if maxLines <= 0 {
224 return nil
225 }
226
227 path := MetricsPath(root)
228 data, err := os.ReadFile(path)
229 if err != nil {
230 if os.IsNotExist(err) {
231 return nil
232 }
233 return err
234 }
235 data = bytes.TrimSpace(data)
236 if len(data) == 0 {
237 return nil
238 }
239
240 lines := bytes.Split(data, []byte("\n"))
241 if len(lines) <= maxLines {
242 return nil
243 }
244
245 trimmed := bytes.Join(lines[len(lines)-maxLines:], []byte("\n"))
246 trimmed = append(trimmed, '\n')
247 tmpPath := path + ".tmp"
248 if err := os.WriteFile(tmpPath, trimmed, 0644); err != nil {
249 return err
250 }
251 return os.Rename(tmpPath, path)
252}

Callers 1

appendMetricsFunction · 0.85

Calls 1

MetricsPathFunction · 0.85

Tested by

no test coverage detected