Merge pull request #3066 from chengzhichao-xydt/codex/tmpfile-close-errors

fix: explicitly ignore Close() errors on temp file write/sync failure paths
This commit is contained in:
Mauro 2026-06-13 18:18:47 +02:00 committed by GitHub
commit f091c04ca9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 4 deletions

View file

@ -334,7 +334,7 @@ func (c *WeComChannel) storeRemoteMedia(
} }
tmpPath := tmpFile.Name() tmpPath := tmpFile.Name()
if _, writeErr := tmpFile.Write(data); writeErr != nil { if _, writeErr := tmpFile.Write(data); writeErr != nil {
tmpFile.Close() _ = tmpFile.Close()
_ = os.Remove(tmpPath) _ = os.Remove(tmpPath)
return "", fmt.Errorf("write temp file: %w", writeErr) return "", fmt.Errorf("write temp file: %w", writeErr)
} }

View file

@ -1111,7 +1111,7 @@ func (r *sandboxFs) WriteFile(path string, data []byte) error {
} }
if _, err := tmpFile.Write(data); err != nil { if _, err := tmpFile.Write(data); err != nil {
tmpFile.Close() _ = tmpFile.Close()
root.Remove(tmpRelPath) root.Remove(tmpRelPath)
return fmt.Errorf("failed to write temp file: %w", err) return fmt.Errorf("failed to write temp file: %w", err)
} }
@ -1119,7 +1119,7 @@ func (r *sandboxFs) WriteFile(path string, data []byte) error {
// CRITICAL: Force sync to storage medium before rename. // CRITICAL: Force sync to storage medium before rename.
// This ensures data is physically written to disk, not just cached. // This ensures data is physically written to disk, not just cached.
if err := tmpFile.Sync(); err != nil { if err := tmpFile.Sync(); err != nil {
tmpFile.Close() _ = tmpFile.Close()
root.Remove(tmpRelPath) root.Remove(tmpRelPath)
return fmt.Errorf("failed to sync temp file: %w", err) return fmt.Errorf("failed to sync temp file: %w", err)
} }

View file

@ -230,7 +230,7 @@ func storeInlineDataURL(
} }
tmpPath := tmpFile.Name() tmpPath := tmpFile.Name()
if _, err = tmpFile.Write(decoded); err != nil { if _, err = tmpFile.Write(decoded); err != nil {
tmpFile.Close() _ = tmpFile.Close()
_ = os.Remove(tmpPath) _ = os.Remove(tmpPath)
return "", fmt.Sprintf("[Tool returned inline media content (%s) but it could not be stored.]", mimeType) return "", fmt.Sprintf("[Tool returned inline media content (%s) but it could not be stored.]", mimeType)
} }