Skip to content

Commit

Permalink
stop using context.TODO in archive handler (#3809)
Browse files Browse the repository at this point in the history
This PR cleans up a context.TODO left by #3743.
  • Loading branch information
rosecodym authored Dec 31, 2024
1 parent 55f0606 commit dde8f8a
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions pkg/handlers/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestAPKHandler(t *testing.T) {

handler := newAPKHandler()

newReader, err := newFileReader(resp.Body)
newReader, err := newFileReader(context.Background(), resp.Body)
if err != nil {
t.Errorf("error creating reusable reader: %s", err)
}
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestOpenInvalidAPK(t *testing.T) {
ctx := logContext.AddLogger(context.Background())
handler := apkHandler{}

rdr, err := newFileReader(io.NopCloser(reader))
rdr, err := newFileReader(ctx, io.NopCloser(reader))
assert.NoError(t, err)
defer rdr.Close()

Expand All @@ -96,7 +96,7 @@ func TestOpenValidZipInvalidAPK(t *testing.T) {

handler := newAPKHandler()

newReader, err := newFileReader(resp.Body)
newReader, err := newFileReader(context.Background(), resp.Body)
if err != nil {
t.Errorf("error creating reusable reader: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/ar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestHandleARFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

rdr, err := newFileReader(file)
rdr, err := newFileReader(ctx, file)
assert.NoError(t, err)
defer rdr.Close()

Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (h *archiveHandler) openArchive(
}
defer compReader.Close()

rdr, err := newFileReader(compReader)
rdr, err := newFileReader(ctx, compReader)
if err != nil {
if errors.Is(err, ErrEmptyReader) {
ctx.Logger().V(5).Info("empty reader, skipping file")
Expand Down Expand Up @@ -226,7 +226,7 @@ func (h *archiveHandler) extractorHandler(dataOrErrChan chan DataOrErr) func(con
}
}()

rdr, err := newFileReader(f)
rdr, err := newFileReader(ctx, f)
if err != nil {
if errors.Is(err, ErrEmptyReader) {
lCtx.Logger().V(5).Info("empty reader, skipping file")
Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestArchiveHandler(t *testing.T) {

handler := newArchiveHandler()

newReader, err := newFileReader(resp.Body)
newReader, err := newFileReader(context.Background(), resp.Body)
if err != nil {
t.Errorf("error creating reusable reader: %s", err)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestOpenInvalidArchive(t *testing.T) {
ctx := logContext.AddLogger(context.Background())
handler := archiveHandler{}

rdr, err := newFileReader(io.NopCloser(reader))
rdr, err := newFileReader(ctx, io.NopCloser(reader))
assert.NoError(t, err)
defer rdr.Close()

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestHandleNonArchiveFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

rdr, err := newFileReader(file)
rdr, err := newFileReader(ctx, file)
assert.NoError(t, err)
defer rdr.Close()

Expand Down
6 changes: 3 additions & 3 deletions pkg/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func newMimeTypeReader(r io.Reader) (mimeTypeReader, error) {

// newFileReader creates a fileReader from an io.Reader, optionally using BufferedFileWriter for certain formats.
// The caller is responsible for closing the reader when it is no longer needed.
func newFileReader(r io.Reader, options ...readerOption) (fReader fileReader, err error) {
func newFileReader(ctx context.Context, r io.Reader, options ...readerOption) (fReader fileReader, err error) {
var cfg readerConfig

for _, opt := range options {
Expand Down Expand Up @@ -154,7 +154,7 @@ func newFileReader(r io.Reader, options ...readerOption) (fReader fileReader, er
}

var format archives.Format
format, _, err = archives.Identify(context.TODO(), "", fReader)
format, _, err = archives.Identify(ctx, "", fReader)
switch {
case err == nil:
fReader.isGenericArchive = true
Expand Down Expand Up @@ -359,7 +359,7 @@ func HandleFile(
}

readerOption := withFileExtension(getFileExtension(chunkSkel))
rdr, err := newFileReader(reader, readerOption)
rdr, err := newFileReader(ctx, reader, readerOption)
if err != nil {
if errors.Is(err, ErrEmptyReader) {
ctx.Logger().V(5).Info("empty reader, skipping file")
Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestHandleRPMFile(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

rdr, err := newFileReader(file)
rdr, err := newFileReader(ctx, file)
assert.NoError(t, err)
defer rdr.Close()

Expand Down

0 comments on commit dde8f8a

Please sign in to comment.