marshalSorted marshals the cache with entries sorted by key
()
| 267 | |
| 268 | // marshalSorted marshals the cache with entries sorted by key |
| 269 | func (c *ActionCache) marshalSorted() ([]byte, error) { |
| 270 | // Extract and sort the entry keys |
| 271 | keys := sliceutil.SortedKeys(c.Entries) |
| 272 | |
| 273 | // Manually construct JSON with sorted keys |
| 274 | var result []byte |
| 275 | result = append(result, []byte("{\n \"entries\": {\n")...) |
| 276 | |
| 277 | for i, key := range keys { |
| 278 | entry := c.Entries[key] |
| 279 | |
| 280 | // Marshal the entry |
| 281 | entryJSON, err := json.MarshalIndent(entry, " ", " ") |
| 282 | if err != nil { |
| 283 | return nil, err |
| 284 | } |
| 285 | |
| 286 | // Add the key and entry |
| 287 | result = append(result, []byte(" \""+key+"\": ")...) |
| 288 | result = append(result, entryJSON...) |
| 289 | |
| 290 | // Add comma if not the last entry |
| 291 | if i < len(keys)-1 { |
| 292 | result = append(result, ',') |
| 293 | } |
| 294 | result = append(result, '\n') |
| 295 | } |
| 296 | |
| 297 | result = append(result, []byte(" }")...) |
| 298 | |
| 299 | // Add containers section if non-empty |
| 300 | if len(c.ContainerPins) > 0 { |
| 301 | pinKeys := sliceutil.SortedKeys(c.ContainerPins) |
| 302 | |
| 303 | result = append(result, []byte(",\n \"containers\": {\n")...) |
| 304 | for i, k := range pinKeys { |
| 305 | pin := c.ContainerPins[k] |
| 306 | pinJSON, err := json.MarshalIndent(pin, " ", " ") |
| 307 | if err != nil { |
| 308 | return nil, err |
| 309 | } |
| 310 | result = append(result, []byte(" \""+k+"\": ")...) |
| 311 | result = append(result, pinJSON...) |
| 312 | if i < len(pinKeys)-1 { |
| 313 | result = append(result, ',') |
| 314 | } |
| 315 | result = append(result, '\n') |
| 316 | } |
| 317 | result = append(result, []byte(" }")...) |
| 318 | } |
| 319 | |
| 320 | result = append(result, '\n', '}') |
| 321 | return result, nil |
| 322 | } |
| 323 | |
| 324 | // Delete removes the cache entry for the given repo and version. |
| 325 | // It first tries the canonical formatted key, then falls back to scanning all |