@@ -338,20 +338,29 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
338338 }
339339 }
340340
341- imgrec := images.Image {
342- Name : name ,
343- Target : desc ,
344- Labels : pullCtx .Labels ,
341+ img := & image {
342+ client : c ,
343+ i : images.Image {
344+ Name : name ,
345+ Target : desc ,
346+ Labels : pullCtx .Labels ,
347+ },
348+ }
349+
350+ if pullCtx .Unpack {
351+ if err := img .Unpack (ctx , pullCtx .Snapshotter ); err != nil {
352+ errors .Wrapf (err , "failed to unpack image on snapshotter %s" , pullCtx .Snapshotter )
353+ }
345354 }
346355
347356 is := c .ImageService ()
348357 for {
349- if created , err := is .Create (ctx , imgrec ); err != nil {
358+ if created , err := is .Create (ctx , img . i ); err != nil {
350359 if ! errdefs .IsAlreadyExists (err ) {
351360 return nil , err
352361 }
353362
354- updated , err := is .Update (ctx , imgrec )
363+ updated , err := is .Update (ctx , img . i )
355364 if err != nil {
356365 // if image was removed, try create again
357366 if errdefs .IsNotFound (err ) {
@@ -360,23 +369,12 @@ func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (Image
360369 return nil , err
361370 }
362371
363- imgrec = updated
372+ img . i = updated
364373 } else {
365- imgrec = created
366- }
367- break
368- }
369-
370- img := & image {
371- client : c ,
372- i : imgrec ,
373- }
374- if pullCtx .Unpack {
375- if err := img .Unpack (ctx , pullCtx .Snapshotter ); err != nil {
376- errors .Wrapf (err , "failed to unpack image on snapshotter %s" , pullCtx .Snapshotter )
374+ img .i = created
377375 }
376+ return img , nil
378377 }
379- return img , nil
380378}
381379
382380// Push uploads the provided content to a remote resource
0 commit comments