MCPcopy Index your code
hub / github.com/regclient/regclient / processRef

Method processRef

cmd/regsync/root.go:656–909  ·  view source on GitHub ↗

process a sync step

(ctx context.Context, s ConfigSync, src, tgt ref.Ref, action actionType)

Source from the content-addressed store, hash-verified

654
655// process a sync step
656func (opts *rootOpts) processRef(ctx context.Context, s ConfigSync, src, tgt ref.Ref, action actionType) error {
657 mSrc, err := opts.rc.ManifestHead(ctx, src, regclient.WithManifestRequireDigest())
658 if err != nil && errors.Is(err, errs.ErrUnsupportedAPI) {
659 mSrc, err = opts.rc.ManifestGet(ctx, src)
660 }
661 if err != nil {
662 opts.log.Error("Failed to lookup source manifest",
663 slog.String("source", src.CommonName()),
664 slog.String("error", err.Error()))
665 return err
666 }
667 fastCheck := (s.FastCheck != nil && *s.FastCheck)
668 forceRecursive := (s.ForceRecursive != nil && *s.ForceRecursive)
669 referrers := (s.Referrers != nil && *s.Referrers)
670 digestTags := (s.DigestTags != nil && *s.DigestTags)
671 mTgt, err := opts.rc.ManifestHead(ctx, tgt, regclient.WithManifestRequireDigest())
672 tgtExists := (err == nil)
673 tgtMatches := false
674 if err == nil && manifest.GetDigest(mSrc).String() == manifest.GetDigest(mTgt).String() {
675 tgtMatches = true
676 }
677 if tgtMatches && (fastCheck || (!forceRecursive && !referrers && !digestTags)) {
678 opts.log.Debug("Image matches",
679 slog.String("source", src.CommonName()),
680 slog.String("target", tgt.CommonName()))
681 return nil
682 }
683 if tgtExists && action == actionMissing {
684 opts.log.Debug("target exists",
685 slog.String("source", src.CommonName()),
686 slog.String("target", tgt.CommonName()))
687 return nil
688 }
689
690 // skip when source manifest is an unsupported type
691 smt := manifest.GetMediaType(mSrc)
692 if !slices.Contains(s.MediaTypes, smt) {
693 opts.log.Info("Skipping unsupported media type",
694 slog.String("ref", src.CommonName()),
695 slog.String("mediaType", manifest.GetMediaType(mSrc)),
696 slog.Any("allowed", s.MediaTypes))
697 return nil
698 }
699
700 // if platform is defined and source is a list, resolve the source platform
701 if mSrc.IsList() && s.Platform != "" {
702 platDigest, err := opts.getPlatformDigest(ctx, src, s.Platform, mSrc)
703 if err != nil {
704 return err
705 }
706 src.Digest = platDigest.String()
707 if tgtExists && platDigest.String() == manifest.GetDigest(mTgt).String() {
708 tgtMatches = true
709 }
710 if tgtMatches && (s.ForceRecursive == nil || !*s.ForceRecursive) {
711 opts.log.Debug("Image matches for platform",
712 slog.String("source", src.CommonName()),
713 slog.String("platform", s.Platform),

Callers 2

TestProcessRefFunction · 0.95
processImageMethod · 0.95

Calls 15

getPlatformDigestMethod · 0.95
GetDigestFunction · 0.92
GetMediaTypeFunction · 0.92
GetRateLimitFunction · 0.92
StringFunction · 0.92
NewFunction · 0.92
ImageWithDigestTagsFunction · 0.92
ImageWithReferrersFunction · 0.92
WithReferrerMatchOptFunction · 0.92
WithReferrerSlowSearchFunction · 0.92
ImageWithReferrerSrcFunction · 0.92

Tested by 1

TestProcessRefFunction · 0.76