From dde8f8a06d5463de2f2cce5e7a8afdcdfccf6b7b Mon Sep 17 00:00:00 2001 From: Cody Rose Date: Tue, 31 Dec 2024 06:29:26 -0800 Subject: [PATCH] stop using context.TODO in archive handler (#3809) This PR cleans up a context.TODO left by #3743. --- pkg/handlers/apk_test.go | 6 +++--- pkg/handlers/ar_test.go | 2 +- pkg/handlers/archive.go | 4 ++-- pkg/handlers/archive_test.go | 4 ++-- pkg/handlers/default_test.go | 2 +- pkg/handlers/handlers.go | 6 +++--- pkg/handlers/rpm_test.go | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/handlers/apk_test.go b/pkg/handlers/apk_test.go index e1f8d13501f2..95075e30f947 100644 --- a/pkg/handlers/apk_test.go +++ b/pkg/handlers/apk_test.go @@ -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) } @@ -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() @@ -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) } diff --git a/pkg/handlers/ar_test.go b/pkg/handlers/ar_test.go index 8658fdafcdff..2f908e4d7c64 100644 --- a/pkg/handlers/ar_test.go +++ b/pkg/handlers/ar_test.go @@ -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() diff --git a/pkg/handlers/archive.go b/pkg/handlers/archive.go index 3f41b1ce45ce..48595096cd03 100644 --- a/pkg/handlers/archive.go +++ b/pkg/handlers/archive.go @@ -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") @@ -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") diff --git a/pkg/handlers/archive_test.go b/pkg/handlers/archive_test.go index 3463b6220c90..7b82b1ebaa8f 100644 --- a/pkg/handlers/archive_test.go +++ b/pkg/handlers/archive_test.go @@ -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) } @@ -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() diff --git a/pkg/handlers/default_test.go b/pkg/handlers/default_test.go index 613ce9dffdea..936a5086d1cf 100644 --- a/pkg/handlers/default_test.go +++ b/pkg/handlers/default_test.go @@ -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() diff --git a/pkg/handlers/handlers.go b/pkg/handlers/handlers.go index e554f6cbb664..f7a2681f1d44 100644 --- a/pkg/handlers/handlers.go +++ b/pkg/handlers/handlers.go @@ -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 { @@ -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 @@ -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") diff --git a/pkg/handlers/rpm_test.go b/pkg/handlers/rpm_test.go index 7ed0e7ad7f6e..ba4d5d622369 100644 --- a/pkg/handlers/rpm_test.go +++ b/pkg/handlers/rpm_test.go @@ -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()