Skip to content

Commit 828d6ed

Browse files
committed
improve close reader
1 parent 2c93060 commit 828d6ed

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

pkg/collect/redact.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
9393
readerCloseFn = func() error { return nil } // No-op for in-memory data
9494
}
9595

96-
// Ensure the reader is closed after processing
97-
defer func() {
98-
if err := readerCloseFn(); err != nil {
99-
klog.Warningf("Failed to close reader for %s: %v", file, err)
100-
errorCh <- errors.Wrap(err, "failed to close reader")
101-
return
102-
}
103-
}()
104-
10596
// If the file is .tar, .tgz or .tar.gz, it must not be redacted. Instead it is
10697
// decompressed and each file inside the tar redacted and compressed back into the archive.
10798
if filepath.Ext(file) == ".tar" || filepath.Ext(file) == ".tgz" || strings.HasSuffix(file, ".tar.gz") {
@@ -117,6 +108,14 @@ func RedactResult(bundlePath string, input CollectorResult, additionalRedactors
117108
errorCh <- errors.Wrap(err, "failed to decompress file")
118109
return
119110
}
111+
112+
// Ensure the reader is closed after processing
113+
if err := readerCloseFn(); err != nil {
114+
klog.Warningf("Failed to close reader for %s: %v", file, err)
115+
errorCh <- errors.Wrap(err, "failed to close reader")
116+
return
117+
}
118+
120119
err = RedactResult(tmpDir, subResult, additionalRedactors)
121120
if err != nil {
122121
errorCh <- errors.Wrap(err, "failed to redact file")

0 commit comments

Comments
 (0)