Skip to content

Commit

Permalink
Merge pull request #1134 from giuseppe/fix-read-zstd-chunked-cache
Browse files Browse the repository at this point in the history
chunked: fix read layer cache
  • Loading branch information
rhatdan authored Feb 14, 2022
2 parents 8825c65 + 26c561f commit 6b7e5c7
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions pkg/chunked/cache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,32 @@ 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)
} else if errors.Cause(err) != os.ErrNotExist {
return err
}

if metadata != nil {
c.addLayer(r.ID, metadata)
continue
}

// 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 6b7e5c7

Please sign in to comment.