copyConfig copies config.json, if any, from src to dest.
(ctx context.Context, src types.Image)
| 617 | |
| 618 | // copyConfig copies config.json, if any, from src to dest. |
| 619 | func (ic *imageCopier) copyConfig(ctx context.Context, src types.Image) error { |
| 620 | srcInfo := src.ConfigInfo() |
| 621 | if srcInfo.Digest != "" { |
| 622 | if err := ic.c.concurrentBlobCopiesSemaphore.Acquire(ctx, 1); err != nil { |
| 623 | // This can only fail with ctx.Err(), so no need to blame acquiring the semaphore. |
| 624 | return fmt.Errorf("copying config: %w", err) |
| 625 | } |
| 626 | defer ic.c.concurrentBlobCopiesSemaphore.Release(1) |
| 627 | |
| 628 | destInfo, err := func() (types.BlobInfo, error) { // A scope for defer |
| 629 | progressPool := ic.c.newProgressPool() |
| 630 | defer progressPool.Wait() |
| 631 | bar, err := ic.c.createProgressBar(progressPool, false, srcInfo, "config", "done") |
| 632 | if err != nil { |
| 633 | return types.BlobInfo{}, err |
| 634 | } |
| 635 | defer bar.Abort(false) |
| 636 | ic.c.printCopyInfo("config", srcInfo) |
| 637 | |
| 638 | configBlob, err := src.ConfigBlob(ctx) |
| 639 | if err != nil { |
| 640 | return types.BlobInfo{}, fmt.Errorf("reading config blob %s: %w", srcInfo.Digest, err) |
| 641 | } |
| 642 | |
| 643 | destInfo, err := ic.copyBlobFromStream(ctx, bytes.NewReader(configBlob), srcInfo, nil, true, false, bar, -1, false) |
| 644 | if err != nil { |
| 645 | return types.BlobInfo{}, err |
| 646 | } |
| 647 | |
| 648 | bar.mark100PercentComplete() |
| 649 | return destInfo, nil |
| 650 | }() |
| 651 | if err != nil { |
| 652 | return err |
| 653 | } |
| 654 | if destInfo.Digest != srcInfo.Digest { |
| 655 | return fmt.Errorf("Internal error: copying uncompressed config blob %s changed digest to %s", srcInfo.Digest, destInfo.Digest) |
| 656 | } |
| 657 | } |
| 658 | return nil |
| 659 | } |
| 660 | |
| 661 | // diffIDResult contains both a digest value and an error from diffIDComputationGoroutine. |
| 662 | // We could also send the error through the pipeReader, but this more cleanly separates the copying of the layer and the DiffID computation. |
no test coverage detected