Skip to content

Commit a36dbcf

Browse files
committed
Move cache/converter.go to util/converter/converter.go
Signed-off-by: Akihiro Suda <[email protected]>
1 parent c7e7f44 commit a36dbcf

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

cache/blobs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/moby/buildkit/session"
1515
"github.com/moby/buildkit/util/bklog"
1616
"github.com/moby/buildkit/util/compression"
17+
"github.com/moby/buildkit/util/converter"
1718
"github.com/moby/buildkit/util/flightcontrol"
1819
"github.com/moby/buildkit/util/winlayers"
1920
digest "github.com/opencontainers/go-digest"
@@ -422,7 +423,7 @@ func ensureCompression(ctx context.Context, ref *immutableRef, comp compression.
422423
}
423424

424425
// Resolve converters
425-
layerConvertFunc, err := getConverter(ctx, ref.cm.ContentStore, desc, comp)
426+
layerConvertFunc, err := converter.New(ctx, ref.cm.ContentStore, desc, comp)
426427
if err != nil {
427428
return struct{}{}, err
428429
} else if layerConvertFunc == nil {

cache/manager_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/moby/buildkit/solver"
4545
"github.com/moby/buildkit/util/compression"
4646
"github.com/moby/buildkit/util/contentutil"
47+
"github.com/moby/buildkit/util/converter"
4748
"github.com/moby/buildkit/util/iohelper"
4849
"github.com/moby/buildkit/util/leaseutil"
4950
"github.com/moby/buildkit/util/overlay"
@@ -1423,7 +1424,7 @@ func testSharingCompressionVariant(ctx context.Context, t *testing.T, co *cmOut,
14231424
require.NoError(t, err, "compression: %v", c)
14241425
uDgst := bDesc.Digest
14251426
if c != compression.Uncompressed {
1426-
convertFunc, err := getConverter(ctx, co.cs, bDesc, compression.New(compression.Uncompressed))
1427+
convertFunc, err := converter.New(ctx, co.cs, bDesc, compression.New(compression.Uncompressed))
14271428
require.NoError(t, err, "compression: %v", c)
14281429
uDesc, err := convertFunc(ctx, co.cs, bDesc)
14291430
require.NoError(t, err, "compression: %v", c)
@@ -1558,7 +1559,7 @@ func TestConversion(t *testing.T) {
15581559
testName := fmt.Sprintf("%s=>%s", i, j)
15591560

15601561
// Prepare the source compression type
1561-
convertFunc, err := getConverter(egctx, store, orgDesc, compSrc)
1562+
convertFunc, err := converter.New(egctx, store, orgDesc, compSrc)
15621563
require.NoError(t, err, testName)
15631564
srcDesc := &orgDesc
15641565
if convertFunc != nil {
@@ -1567,7 +1568,7 @@ func TestConversion(t *testing.T) {
15671568
}
15681569

15691570
// Convert the blob
1570-
convertFunc, err = getConverter(egctx, store, *srcDesc, compDest)
1571+
convertFunc, err = converter.New(egctx, store, *srcDesc, compDest)
15711572
require.NoError(t, err, testName)
15721573
resDesc := srcDesc
15731574
if convertFunc != nil {
@@ -1576,7 +1577,7 @@ func TestConversion(t *testing.T) {
15761577
}
15771578

15781579
// Check the uncompressed digest is the same as the original
1579-
convertFunc, err = getConverter(egctx, store, *resDesc, compression.New(compression.Uncompressed))
1580+
convertFunc, err = converter.New(egctx, store, *resDesc, compression.New(compression.Uncompressed))
15801581
require.NoError(t, err, testName)
15811582
recreatedDesc := resDesc
15821583
if convertFunc != nil {

cache/converter.go renamed to util/converter/converter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cache
1+
package converter
22

33
import (
44
"bufio"
@@ -20,9 +20,9 @@ import (
2020
"github.com/pkg/errors"
2121
)
2222

23-
// getConverter returns converter function according to the specified compression type.
23+
// New returns converter function according to the specified compression type.
2424
// If no conversion is needed, this returns nil without error.
25-
func getConverter(ctx context.Context, cs content.Store, desc ocispecs.Descriptor, comp compression.Config) (converter.ConvertFunc, error) {
25+
func New(ctx context.Context, cs content.Store, desc ocispecs.Descriptor, comp compression.Config) (converter.ConvertFunc, error) {
2626
if needs, err := comp.Type.NeedsConversion(ctx, cs, desc); err != nil {
2727
return nil, errors.Wrapf(err, "failed to determine conversion needs")
2828
} else if !needs {

0 commit comments

Comments
 (0)