Skip to content

Commit 9ba7a05

Browse files
committed
addressing bugbot concerns
1 parent 588460c commit 9ba7a05

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

pkg/collect/host_network.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ func checkTCPConnection(progressChan chan<- interface{}, listenAddress string, d
112112
if time.Now().After(stopAfter) {
113113
debug.Printf("Timeout")
114114

115-
return NetworkStatusConnectionTimeout, "", errors.New("connection timeout")
115+
errMsg := "connection timeout"
116+
return NetworkStatusConnectionTimeout, errMsg, errors.New(errMsg)
116117
}
117118

118119
conn, err := net.DialTimeout("tcp", dialAddress, 50*time.Millisecond)

pkg/collect/result.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,15 @@ func (r CollectorResult) ReplaceResult(bundlePath string, relativePath string, r
204204
tmpFileName := tmpFile.Name()
205205

206206
// Ensure cleanup of temp file on error
207+
cleanupNeeded := true
207208
defer func() {
208209
if tmpFile != nil {
209-
tmpFile.Close()
210-
os.Remove(tmpFileName)
210+
// Best-effort close in defer; ignore close errors here
211+
_ = tmpFile.Close()
212+
}
213+
if cleanupNeeded {
214+
// Best-effort remove of temp file if we didn't successfully rename it
215+
_ = os.Remove(tmpFileName)
211216
}
212217
}()
213218

@@ -234,6 +239,8 @@ func (r CollectorResult) ReplaceResult(bundlePath string, relativePath string, r
234239
if err != nil {
235240
return errors.Wrap(err, "failed to rename tmp file")
236241
}
242+
// If rename succeeded, no need to clean up the temp file path
243+
cleanupNeeded = false
237244

238245
return nil
239246
}
@@ -375,7 +382,7 @@ func (r CollectorResult) ArchiveBundle(bundlePath string, outputFilename string)
375382
return errors.Wrap(err, "failed to write tar header")
376383
}
377384

378-
func() error {
385+
err = func() error {
379386
if fileMode.Type() == os.ModeSymlink {
380387
// Don't copy the symlink, just write the header which
381388
// will create a symlink in the tarball

0 commit comments

Comments
 (0)