From 9d18b57469c52b6f919370c4ee9da136290abb39 Mon Sep 17 00:00:00 2001 From: James Jenkins Date: Thu, 29 Sep 2022 10:24:45 -0400 Subject: [PATCH] Modify WithDiscardUnpackedLayers Modify the WithDiscardUnpackedLayers function such that it does not require any parameters. Signed-off-by: James Jenkins --- cmd/ctr/commands/images/import.go | 8 +++++--- import.go | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cmd/ctr/commands/images/import.go b/cmd/ctr/commands/images/import.go index fa1f1d801..8b94d0cea 100644 --- a/cmd/ctr/commands/images/import.go +++ b/cmd/ctr/commands/images/import.go @@ -136,10 +136,12 @@ If foobar.tar contains an OCI ref named "latest" and anonymous ref "sha256:deadb opts = append(opts, containerd.WithAllPlatforms(context.Bool("all-platforms"))) - if context.Bool("discard-unpacked-layers") && context.Bool("no-unpack") { - return fmt.Errorf("--discard-unpacked-layers and --no-unpack are incompatible options") + if context.Bool("discard-unpacked-layers") { + if context.Bool("no-unpack") { + return fmt.Errorf("--discard-unpacked-layers and --no-unpack are incompatible options") + } + opts = append(opts, containerd.WithDiscardUnpackedLayers()) } - opts = append(opts, containerd.WithDiscardUnpackedLayers(context.Bool("discard-unpacked-layers"))) client, ctx, cancel, err := commands.NewClient(context) if err != nil { diff --git a/import.go b/import.go index 98e94df1f..ca55920dc 100644 --- a/import.go +++ b/import.go @@ -108,9 +108,9 @@ func WithImportCompression() ImportOpt { // WithDiscardUnpackedLayers allows the garbage collector to clean up // layers from content store after unpacking. -func WithDiscardUnpackedLayers(discard bool) ImportOpt { +func WithDiscardUnpackedLayers() ImportOpt { return func(c *importOpts) error { - c.discardLayers = discard + c.discardLayers = true return nil } }