Skip to content

Commit

Permalink
improve clpse reader
Browse files Browse the repository at this point in the history
  • Loading branch information
DexterYan committed Feb 4, 2025
1 parent 2c93060 commit 966423f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/collect/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
readerCloseFn = func() error { return nil } // No-op for in-memory data
}

// Ensure the reader is closed after processing
defer func() {
if err := readerCloseFn(); err != nil {
klog.Warningf("Failed to close reader for %s: %v", file, err)
errorCh <- errors.Wrap(err, "failed to close reader")
return
}
}()

// If the file is .tar, .tgz or .tar.gz, it must not be redacted. Instead it is
// decompressed and each file inside the tar redacted and compressed back into the archive.
if filepath.Ext(file) == ".tar" || filepath.Ext(file) == ".tgz" || strings.HasSuffix(file, ".tar.gz") {
Expand All @@ -117,6 +108,14 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
errorCh <- errors.Wrap(err, "failed to decompress file")
return
}

// Ensure the reader is closed after processing
if err := readerCloseFn(); err != nil {
klog.Warningf("Failed to close reader for %s: %v", file, err)
errorCh <- errors.Wrap(err, "failed to close reader")
return
}

err = RedactResult(tmpDir, subResult, additionalRedactors)
if err != nil {
errorCh <- errors.Wrap(err, "failed to redact file")
Expand Down

0 comments on commit 966423f

Please sign in to comment.