Skip to content

Commit

Permalink
aws: ensure Close call gets to underlying File
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed May 29, 2020
1 parent a0c9aaa commit 7518c5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 17 additions & 1 deletion aws/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aws

import (
"compress/gzip"
"context"
"encoding/xml"
"fmt"
Expand Down Expand Up @@ -150,15 +151,30 @@ func (c *Client) Updates(ctx context.Context) (io.ReadCloser, error) {
tf.Close()
return nil, err
}
gz, err := gzip.NewReader(tf)
if err != nil {
return nil, fmt.Errorf("failed to create gzip reader: %v", err)
}

log.Debug().Msg("success")
return tf, nil
return &gzippedFile{
Reader: gz,
Closer: tf,
}, nil
}

log.Error().Msg("exhausted all mirrors")
return nil, fmt.Errorf("all update_info mirrors failed to return a response")
}

// gzippedFile implements io.ReadCloser by proxying calls to different
// underlying implementations. This is used to make sure the file that backs the
// downloaded security database has Close called on it.
type gzippedFile struct {
io.Reader
io.Closer
}

func (c *Client) getMirrors(ctx context.Context, release Release) error {
var (
req *http.Request
Expand Down
8 changes: 0 additions & 8 deletions aws/updater.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package aws

import (
"compress/gzip"
"context"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"strings"
"time"

Expand Down Expand Up @@ -59,12 +57,6 @@ func (u *Updater) Fetch(ctx context.Context, fingerprint driver.Fingerprint) (io
return nil, "", fmt.Errorf("failed to retrieve update info: %v", err)
}

gzip, err := gzip.NewReader(rc)
if err != nil {
return nil, "", fmt.Errorf("failed to create gzip reader: %v", err)
}
rc = ioutil.NopCloser(gzip)

return rc, driver.Fingerprint(updatesRepoMD.Checksum.Sum), nil
}

Expand Down

0 comments on commit 7518c5f

Please sign in to comment.