Skip to content

Commit

Permalink
chunked: fix read layer cache
Browse files Browse the repository at this point in the history
if the layer cache doesn't already exist, automatically create it from
the layer TOC.

commit 10697a0 introduced this
regression.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Feb 14, 2022
1 parent 8825c65 commit d12718e
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions pkg/chunked/cache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,33 @@ func (c *layersCache) load() error {
}

bigData, err := c.store.LayerBigData(r.ID, cacheKey)
if err != nil {
if errors.Cause(err) == os.ErrNotExist {
// if the cache areadly exists, read and use it
if err == nil {
defer bigData.Close()
metadata, err := readMetadataFromCache(bigData)
if err == nil {
c.addLayer(r.ID, metadata)
continue
}
return err
}
defer bigData.Close()

metadata, err := readMetadataFromCache(bigData)
if err != nil {
logrus.Warningf("Error reading cache file for layer %q: %v", r.ID, err)
}

if metadata != nil {
c.addLayer(r.ID, metadata)
continue
if errors.Cause(err) != os.ErrNotExist {
return err
}

// otherwise create it from the layer TOC.
manifestReader, err := c.store.LayerBigData(r.ID, bigDataKey)
if err != nil {
continue
}
defer manifestReader.Close()

manifest, err := ioutil.ReadAll(manifestReader)
if err != nil {
return fmt.Errorf("open manifest file for layer %q: %w", r.ID, err)
}

metadata, err = writeCache(manifest, r.ID, c.store)
metadata, err := writeCache(manifest, r.ID, c.store)
if err == nil {
c.addLayer(r.ID, metadata)
}
Expand Down

0 comments on commit d12718e

Please sign in to comment.