Skip to content

Commit

Permalink
feat(daemon): avoid multiple initialization (#1126)
Browse files Browse the repository at this point in the history
* feat(daemon): avoid multiple initialization

* Use sync.Once
  • Loading branch information
knqyf263 committed Sep 21, 2021
1 parent 40ba044 commit 486e71f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/v1/daemon/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type image struct {
ref name.Reference
opener *imageOpener
tarballImage v1.Image

once sync.Once
err error
}

type imageOpener struct {
Expand Down Expand Up @@ -101,13 +104,11 @@ func Image(ref name.Reference, options ...Option) (v1.Image, error) {
func (i *image) initialize() error {
// Don't re-initialize tarball if already initialized.
if i.tarballImage == nil {
var err error
i.tarballImage, err = tarball.Image(i.opener.opener(), nil)
if err != nil {
return err
}
i.once.Do(func() {
i.tarballImage, i.err = tarball.Image(i.opener.opener(), nil)
})
}
return nil
return i.err
}

func (i *image) Layers() ([]v1.Layer, error) {
Expand Down

0 comments on commit 486e71f

Please sign in to comment.