Skip to content

Commit

Permalink
Merge pull request docker#2230 from jedevc/imagetools-resolver-copy-dupe
Browse files Browse the repository at this point in the history
fix: avoid modifying source during resolver.Copy
  • Loading branch information
jedevc authored Feb 1, 2024
2 parents 082d5d7 + 95bdecc commit 8968402
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions util/imagetools/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"maps"
"net/url"
"strings"

Expand Down Expand Up @@ -230,13 +231,17 @@ func (r *Resolver) Copy(ctx context.Context, src *Source, dest reference.Named)
if err != nil {
return err
}
source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/")
if src.Desc.Annotations == nil {
src.Desc.Annotations = make(map[string]string)

desc := src.Desc
desc.Annotations = maps.Clone(desc.Annotations)
if desc.Annotations == nil {
desc.Annotations = make(map[string]string)
}
src.Desc.Annotations["containerd.io/distribution.source."+source] = repo

err = contentutil.CopyChain(ctx, contentutil.FromPusher(p), contentutil.FromFetcher(f), src.Desc)
source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/")
desc.Annotations["containerd.io/distribution.source."+source] = repo

err = contentutil.CopyChain(ctx, contentutil.FromPusher(p), contentutil.FromFetcher(f), desc)
if err != nil {
return err
}
Expand Down

0 comments on commit 8968402

Please sign in to comment.