Skip to content

Commit

Permalink
oci: walk: return error from Close if applicable
Browse files Browse the repository at this point in the history
Since we are reading blobs we should definitely be returning errors from
the lookup.

Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Mar 29, 2021
1 parent 1f954d4 commit 3c9687b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions oci/casext/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ var ErrSkipDescriptor = errors.New("[internal] do not recurse into descriptor")
// more than once. This is quite important for remote CAS implementations.
type WalkFunc func(descriptorPath DescriptorPath) error

func (ws *walkState) recurse(ctx context.Context, descriptorPath DescriptorPath) error {
func (ws *walkState) recurse(ctx context.Context, descriptorPath DescriptorPath) (Err error) {
log.WithFields(log.Fields{
"digest": descriptorPath.Descriptor().Digest,
}).Debugf("-> ws.recurse")
Expand Down Expand Up @@ -129,7 +129,15 @@ func (ws *walkState) recurse(ctx context.Context, descriptorPath DescriptorPath)
}
return err
}
defer blob.Close()
defer func() {
if err := blob.Close(); err != nil {
if Err == nil {
err = Err
} else {
log.Warnf("during recursion blob %v had error on Close: %v", descriptor.Digest, err)
}
}
}()

// Recurse into children.
for _, child := range childDescriptors(blob.Data) {
Expand Down

0 comments on commit 3c9687b

Please sign in to comment.