Skip to content

Commit

Permalink
oci exporter: rename unpack option to tar option
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Chadwell <[email protected]>
  • Loading branch information
jedevc committed Nov 17, 2022
1 parent 2c3637f commit 819bd34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestIntegration(t *testing.T) {
testResolveAndHosts,
testUser,
testOCIExporter,
testOCIExporterUnpack,
testOCIExporterContentStore,
testWhiteoutParentDir,
testFrontendImageNaming,
testDuplicateWhiteouts,
Expand Down Expand Up @@ -2356,7 +2356,7 @@ func testOCIExporter(t *testing.T, sb integration.Sandbox) {
checkAllReleasable(t, c, sb, true)
}

func testOCIExporterUnpack(t *testing.T, sb integration.Sandbox) {
func testOCIExporterContentStore(t *testing.T, sb integration.Sandbox) {
integration.SkipIfDockerd(t, sb, "oci exporter")
requiresLinux(t)
c, err := New(sb.Context(), sb.Address())
Expand Down Expand Up @@ -2400,7 +2400,7 @@ func testOCIExporterUnpack(t *testing.T, sb integration.Sandbox) {

outDir := filepath.Join(destDir, "out.d")
attrs = map[string]string{
"unpack": "true",
"tar": "false",
}
if exp == ExporterDocker {
attrs["name"] = target
Expand Down
37 changes: 19 additions & 18 deletions exporter/oci/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const (
)

const (
keyUnpack = "unpack"
keyTar = "tar"
)

type Opt struct {
Expand All @@ -62,6 +62,7 @@ func New(opt Opt) (exporter.Exporter, error) {
func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exporter.ExporterInstance, error) {
i := &imageExporterInstance{
imageExporter: e,
tar: true,
opts: containerimage.ImageCommitOpts{
RefCfg: cacheconfig.RefConfig{
Compression: compression.New(compression.Default),
Expand All @@ -78,16 +79,16 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp

for k, v := range opt {
switch k {
case keyUnpack:
case keyTar:
if v == "" {
i.unpack = true
i.tar = true
continue
}
b, err := strconv.ParseBool(v)
if err != nil {
return nil, errors.Wrapf(err, "non-bool value specified for %s", k)
}
i.unpack = b
i.tar = b
default:
if i.meta == nil {
i.meta = make(map[string][]byte)
Expand All @@ -100,9 +101,9 @@ func (e *imageExporter) Resolve(ctx context.Context, opt map[string]string) (exp

type imageExporterInstance struct {
*imageExporter
opts containerimage.ImageCommitOpts
unpack bool
meta map[string][]byte
opts containerimage.ImageCommitOpts
tar bool
meta map[string][]byte
}

func (e *imageExporterInstance) Name() string {
Expand Down Expand Up @@ -237,17 +238,7 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
}
}

if e.unpack {
ctx = remotes.WithMediaTypeKeyPrefix(ctx, intoto.PayloadType, "intoto")
store := sessioncontent.NewCallerStore(caller, "export")
if err != nil {
return nil, err
}
err := contentutil.CopyChain(ctx, store, mprovider, *desc)
if err != nil {
return nil, err
}
} else {
if e.tar {
w, err := filesync.CopyFileWriter(ctx, resp, caller)
if err != nil {
return nil, err
Expand All @@ -269,6 +260,16 @@ func (e *imageExporterInstance) Export(ctx context.Context, src *exporter.Source
return nil, report(err)
}
report(nil)
} else {
ctx = remotes.WithMediaTypeKeyPrefix(ctx, intoto.PayloadType, "intoto")
store := sessioncontent.NewCallerStore(caller, "export")
if err != nil {
return nil, err
}
err := contentutil.CopyChain(ctx, store, mprovider, *desc)
if err != nil {
return nil, err
}
}

return resp, nil
Expand Down

0 comments on commit 819bd34

Please sign in to comment.