buildLayerInfosForCopy builds a LayerInfosForCopy return value based on manifestInfos from the original manifest, but using layer data which we can actually produce — physicalInfos for non-empty layers, and image.GzippedEmptyLayer for empty ones. (This is split basically only to allow easily unit-te
(manifestInfos []manifest.LayerInfo, physicalInfos []types.BlobInfo)
| 359 | // and image.GzippedEmptyLayer for empty ones. |
| 360 | // (This is split basically only to allow easily unit-testing the part that has no dependencies on the external environment.) |
| 361 | func buildLayerInfosForCopy(manifestInfos []manifest.LayerInfo, physicalInfos []types.BlobInfo) ([]types.BlobInfo, error) { |
| 362 | nextPhysical := 0 |
| 363 | res := make([]types.BlobInfo, len(manifestInfos)) |
| 364 | for i, mi := range manifestInfos { |
| 365 | if mi.EmptyLayer { |
| 366 | res[i] = types.BlobInfo{ |
| 367 | Digest: image.GzippedEmptyLayerDigest, |
| 368 | Size: int64(len(image.GzippedEmptyLayer)), |
| 369 | MediaType: mi.MediaType, |
| 370 | } |
| 371 | } else { |
| 372 | if nextPhysical >= len(physicalInfos) { |
| 373 | return nil, fmt.Errorf("expected more than %d physical layers to exist", len(physicalInfos)) |
| 374 | } |
| 375 | res[i] = physicalInfos[nextPhysical] // FIXME? Should we preserve more data in manifestInfos? Notably the current approach correctly removes zstd:chunked metadata annotations. |
| 376 | nextPhysical++ |
| 377 | } |
| 378 | } |
| 379 | if nextPhysical != len(physicalInfos) { |
| 380 | return nil, fmt.Errorf("used only %d out of %d physical layers", nextPhysical, len(physicalInfos)) |
| 381 | } |
| 382 | return res, nil |
| 383 | } |
| 384 | |
| 385 | // GetSignaturesWithFormat returns the image's signatures. It may use a remote (= slow) service. |
| 386 | // If instanceDigest is not nil, it contains a digest of the specific manifest instance to retrieve signatures for |
no outgoing calls
searching dependent graphs…