Repository: moby/moby
File: daemon/containerd/image_push.go (Go)

Code before:
	realStore := store
	wrapped := wrapWithFakeMountableBlobs(store, mountableBlobs)
	store = wrapped
	addLayerJobs := c8dimages.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
		if showBlobProgress(desc) {
			jobsQueue.Add(desc)
		}

		return nil, nil
	})

	handlerWrapper := func(h c8dimages.Handler) c8dimages.Handler {
		return c8dimages.Handlers(addLayerJobs, h)
	}

	push := func(ctx context.Context, desc ocispec.Descriptor) error {
		ref := targetRef

		if _, digested := ref.(reference.Digested); !digested {
			// Annotate ref with digest to push only push tag for single digest
			ref, err = reference.WithDigest(ref, target.Digest)
			if err != nil {
				return err
			}
		}
		pusher, err := resolver.Pusher(ctx, targetRef.String())
		if err != nil {
			return err
		}

		return remotes.PushContent(ctx, pusher, desc, store, limiter, platforms.All, handlerWrapper)
	}

	err = push(ctx, target)
	if err != nil {
		// If push failed because of a missing content, no specific platform was requested
		// and the target is an index, select a platform-specific manifest to push instead.
		if cerrdefs.IsNotFound(err) && c8dimages.IsIndexType(target.MediaType) && platform == nil {
			var newTarget ocispec.Descriptor
			newTarget, err = i.getPushDescriptor(ctx, img, nil)
			if err != nil {
				return err
			}

			// Retry only if the new push candidate is different from the previous one.
			if newTarget.Digest != target.Digest {
				orgTarget := target
				target = newTarget
				pp.TurnNotStartedIntoUnavailable()
				err = push(ctx, target)


Review comment (suggestion):
oh! this should be `ref` ?

```suggestion
		pusher, err := resolver.Pusher(ctx, ref.String())
```


The linter spotted it (and I missed it);

```
daemon/containerd/image_push.go:163:4: ineffectual assignment to ref (ineffassign)
			ref, err = reference.WithDigest(ref, target.Digest)
			^
```

Code after:
	realStore := store
	wrapped := wrapWithFakeMountableBlobs(store, mountableBlobs)
	store = wrapped
	addLayerJobs := c8dimages.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
		if showBlobProgress(desc) {
			jobsQueue.Add(desc)
		}

		return nil, nil
	})

	handlerWrapper := func(h c8dimages.Handler) c8dimages.Handler {
		return c8dimages.Handlers(addLayerJobs, h)
	}

	push := func(ctx context.Context, desc ocispec.Descriptor) error {
		ref := targetRef

		if _, digested := ref.(reference.Digested); !digested {
			// Annotate ref with digest to push only push tag for single digest
			ref, err = reference.WithDigest(ref, target.Digest)
			if err != nil {
				return err
			}
		}
		pusher, err := resolver.Pusher(ctx, ref.String())
		if err != nil {
			return err
		}

		return remotes.PushContent(ctx, pusher, desc, store, limiter, platforms.All, handlerWrapper)
	}

	err = push(ctx, target)
	if err != nil {
		// If push failed because of a missing content, no specific platform was requested
		// and the target is an index, select a platform-specific manifest to push instead.
		if cerrdefs.IsNotFound(err) && c8dimages.IsIndexType(target.MediaType) && platform == nil {
			var newTarget ocispec.Descriptor
			newTarget, err = i.getPushDescriptor(ctx, img, nil)
			if err != nil {
				return err
			}

			// Retry only if the new push candidate is different from the previous one.
			if newTarget.Digest != target.Digest {
				orgTarget := target
				target = newTarget
				pp.TurnNotStartedIntoUnavailable()
				err = push(ctx, target)