Skip to content

Commit

Permalink
FIXME: Inline singleLayerIDComponent into its only caller
Browse files Browse the repository at this point in the history
commitLayer already contains detailed logic for computing
the final layer ID (chain ID), so having the detailed logic
for the single layer component in a separate function is not
any clearer.

Should not change behavior.

Instead, outline the whole thing and add unit tests.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Nov 28, 2024
1 parent b8ac37e commit 44c52a4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions storage/storage_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,6 @@ func (s *storageImageDestination) queueOrCommit(index int, info addedLayerInfo)
return nil
}

// singleLayerIDComponent returns a single layer’s the input to computing a layer (chain) ID,
// and an indication whether the input already has the shape of a layer ID.
func (trusted trustedLayerIdentityData) singleLayerIDComponent() (string, bool) {
if trusted.layerIdentifiedByTOC {
return "@TOC=" + trusted.tocDigest.Encoded(), false // "@" is not a valid start of a digest.Digest, so this is unambiguous.
}
return trusted.diffID.Encoded(), true // This looks like chain IDs, and it uses the traditional value.
}

// commitLayer commits the specified layer with the given index to the storage.
// size can usually be -1; it can be provided if the layer is not known to be already present in blobDiffIDs.
//
Expand Down Expand Up @@ -907,9 +898,14 @@ func (s *storageImageDestination) commitLayer(index int, info addedLayerInfo, si
}
}
// The layerID refers either to the DiffID or the digest of the TOC.
layerIDComponent, layerIDComponentStandalone := trusted.singleLayerIDComponent()
var layerIDComponent string
if trusted.layerIdentifiedByTOC {
layerIDComponent = "@TOC=" + trusted.tocDigest.Encoded() // "@" is not a valid start of a digest.Digest, so this is unambiguous.
} else {
layerIDComponent = trusted.diffID.Encoded() // This looks like chain IDs, and it uses the traditional value.
}
id := layerIDComponent
if !layerIDComponentStandalone || parentLayer != "" {
if trusted.layerIdentifiedByTOC || parentLayer != "" {
id = digest.Canonical.FromString(parentLayer + "+" + layerIDComponent).Encoded()
}
if layer, err2 := s.imageRef.transport.store.Layer(id); layer != nil && err2 == nil {
Expand Down

0 comments on commit 44c52a4

Please sign in to comment.