Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using context.TODO in archive handler #3809

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading