Skip to content

Commit 7f7f270

Browse files
committed
fix: fix load image failed
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
1 parent 0b388bb commit 7f7f270

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

pkg/imgutil/load/load.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ func FromArchive(ctx context.Context, client *containerd.Client, options types.I
6060
}
6161

6262
imageService := client.ImageService()
63-
beforeImages, err := imageService.List(ctx)
64-
if err != nil {
65-
return nil, err
66-
}
67-
beforeSet := make(map[string]bool)
68-
for _, img := range beforeImages {
69-
beforeSet[img.Name] = true
70-
}
7163

7264
var storeOpts []transferimage.StoreOpt
7365
platUnpack := platforms.DefaultSpec()
@@ -86,24 +78,23 @@ func FromArchive(ctx context.Context, client *containerd.Client, options types.I
8678

8779
var loadedImages []images.Image
8880
pf, done := transferutil.ProgressHandler(ctx, options.Stdout)
89-
90-
err = client.Transfer(ctx,
81+
ch := make(chan struct{})
82+
err := client.Transfer(ctx,
9183
tarchive.NewImageImportStream(options.Stdin, ""),
9284
transferimage.NewStore("", storeOpts...),
9385
transfer.WithProgress(func(p transfer.Progress) {
9486
if p.Event == "saved" {
87+
defer close(ch)
9588
if img, err := imageService.Get(ctx, p.Name); err == nil {
96-
if !beforeSet[img.Name] {
97-
loadedImages = append(loadedImages, img)
98-
}
89+
loadedImages = append(loadedImages, img)
9990
}
10091
}
10192
pf(p)
10293
}),
10394
)
10495

10596
done()
106-
97+
<-ch
10798
if !options.Quiet {
10899
for _, img := range loadedImages {
109100
fmt.Fprintf(options.Stdout, "Loaded image: %s\n", img.Name)

0 commit comments

Comments
 (0)