Skip to content

Commit

Permalink
download: Fix saving OCI bundles on disk
Browse files Browse the repository at this point in the history
This commit fixes an issue related to zero-sized bundles being saved to disk,
which can cause OPA to fail to start if a remote OCI repository is unavailable.

Fixes: #6939

Signed-off-by: Sergey-Kizimov <serget.kizimov@hiya.com>
  • Loading branch information
Sergey-Kizimov committed Aug 20, 2024
1 parent a94d87f commit 7b41d70
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions download/oci_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package download

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -217,6 +218,7 @@ func (d *OCIDownloader) oneShot(ctx context.Context) error {

func (d *OCIDownloader) download(ctx context.Context, m metrics.Metrics) (*downloaderResponse, error) {
d.logger.Debug("OCI - Download starting.")
var buf bytes.Buffer

preferences := []string{fmt.Sprintf("modes=%v,%v", defaultBundleMode, deltaBundleMode)}

Expand Down Expand Up @@ -256,10 +258,12 @@ func (d *OCIDownloader) download(ctx context.Context, m metrics.Metrics) (*downl
}, nil
}
fileReader, err := os.Open(bundleFilePath)
tee := io.TeeReader(fileReader, &buf)

if err != nil {
return nil, err
}
loader := bundle.NewTarballLoaderWithBaseURL(fileReader, d.localStorePath)
loader := bundle.NewTarballLoaderWithBaseURL(tee, d.localStorePath)
reader := bundle.NewCustomReader(loader).
WithMetrics(m).
WithBundleVerificationConfig(d.bvc).
Expand All @@ -274,7 +278,7 @@ func (d *OCIDownloader) download(ctx context.Context, m metrics.Metrics) (*downl

return &downloaderResponse{
b: &bundleInfo,
raw: fileReader,
raw: &buf,
etag: etag,
longPoll: false,
}, nil
Expand Down

0 comments on commit 7b41d70

Please sign in to comment.