Skip to content

Commit

Permalink
Remove uses of deprecated go-digest.NewDigestFromHex, go-digest.Diges…
Browse files Browse the repository at this point in the history
…t.Hex

Both of these were deprecated in opencontainers/go-digest@55f6758,
but the format of the GoDoc comments didn't follow the correct format, which
caused them not being picked up by tools as "deprecated".

This patch updates uses in the codebase to use the alternatives.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Nov 8, 2022
1 parent e9a25da commit bf72536
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions manifest/schema1/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,26 @@ func (mb *configManifestBuilder) Build(ctx context.Context) (m distribution.Mani
layerCounter++
}

v1ID := digest.FromBytes([]byte(blobsum.Hex() + " " + parent)).Hex()
v1ID := digest.FromBytes([]byte(blobsum.Encoded() + " " + parent)).Encoded()

if i == 0 && img.RootFS.BaseLayer != "" {
// windows-only baselayer setup
baseID := sha512.Sum384([]byte(img.RootFS.BaseLayer))
parent = fmt.Sprintf("%x", baseID[:32])
}

v1Compatibility := v1Compatibility{
v1Compat := v1Compatibility{
ID: v1ID,
Parent: parent,
Comment: h.Comment,
Created: h.Created,
Author: h.Author,
}
v1Compatibility.ContainerConfig.Cmd = []string{img.History[i].CreatedBy}
v1Compat.ContainerConfig.Cmd = []string{img.History[i].CreatedBy}
if h.EmptyLayer {
v1Compatibility.ThrowAway = true
v1Compat.ThrowAway = true
}
jsonBytes, err := json.Marshal(&v1Compatibility)
jsonBytes, err := json.Marshal(&v1Compat)
if err != nil {
return nil, err
}
Expand All @@ -178,11 +178,11 @@ func (mb *configManifestBuilder) Build(ctx context.Context) (m distribution.Mani
}

fsLayerList[0] = FSLayer{BlobSum: blobsum}
dgst := digest.FromBytes([]byte(blobsum.Hex() + " " + parent + " " + string(mb.configJSON)))
dgst := digest.FromBytes([]byte(blobsum.Encoded() + " " + parent + " " + string(mb.configJSON)))

// Top-level v1compatibility string should be a modified version of the
// image config.
transformedConfig, err := MakeV1ConfigFromConfig(mb.configJSON, dgst.Hex(), parent, latestHistory.EmptyLayer)
transformedConfig, err := MakeV1ConfigFromConfig(mb.configJSON, dgst.Encoded(), parent, latestHistory.EmptyLayer)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion registry/storage/linkedblobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestLinkedBlobStoreCreateWithMountFrom(t *testing.T) {
// cross-repo mount them into a nm/baz and provide a prepopulated blob descriptor
for dgst := range testLayers {
fooCanonical, _ := reference.WithDigest(fooRepoName, dgst)
size, err := strconv.ParseInt("0x"+dgst.Hex()[:8], 0, 64)
size, err := strconv.ParseInt("0x"+dgst.Encoded()[:8], 0, 64)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions registry/storage/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func digestPathComponents(dgst digest.Digest, multilevel bool) ([]string, error)
}

algorithm := blobAlgorithmReplacer.Replace(string(dgst.Algorithm()))
hex := dgst.Hex()
hex := dgst.Encoded()
prefix := []string{algorithm}

var suffix []string
Expand Down Expand Up @@ -480,6 +480,6 @@ func digestFromPath(digestPath string) (digest.Digest, error) {
algo = next
}

dgst := digest.NewDigestFromHex(algo, hex)
dgst := digest.NewDigestFromEncoded(digest.Algorithm(algo), hex)
return dgst, dgst.Validate()
}

0 comments on commit bf72536

Please sign in to comment.