diff --git a/repo.go b/repo.go index e22b3558..0c1ab7d1 100644 --- a/repo.go +++ b/repo.go @@ -696,7 +696,7 @@ func (r *Repo) AddTargets(paths []string, custom json.RawMessage) error { return r.AddTargetsWithExpires(paths, custom, data.DefaultExpires("targets")) } -func (r *Repo) AddDigestTargets(digest string, digestAlg string, length int64, custom json.RawMessage, path string) error { +func (r *Repo) AddTargetsWithDigest(digest string, digestAlg string, length int64, custom json.RawMessage, path string) error { expires := data.DefaultExpires("targets") // TODO: support delegated targets @@ -711,6 +711,8 @@ func (r *Repo) AddDigestTargets(digest string, digestAlg string, length int64, c return err } + // If custom is provided, set custom, otherwise maintain existing custom + // metadata if len(custom) > 0 { meta.Custom = &custom } else if t, ok := t.Targets[path]; ok { diff --git a/repo_test.go b/repo_test.go index 287acae0..f8d804f8 100644 --- a/repo_test.go +++ b/repo_test.go @@ -1761,7 +1761,7 @@ func (rs *RepoSuite) TestSignDigest(c *C) { hash := "bc11b176a293bb341a0f2d0d226f52e7fcebd186a7c4dfca5fc64f305f06b94c" size := int64(42) - c.Assert(r.AddDigestTargets(hash, "sha256", size, nil, digest), IsNil) + c.Assert(r.AddTargetsWithDigest(hash, "sha256", size, nil, digest), IsNil) c.Assert(r.Snapshot(), IsNil) c.Assert(r.Timestamp(), IsNil) c.Assert(r.Commit(), IsNil)