fix(pcap): try to fix file handle error

This commit is contained in:
2025-10-12 12:03:33 +01:00
parent 53fa68b525
commit 80632dd1d9

View File

@@ -31,8 +31,12 @@ func NewPacketCapture(iface, outputPath string) (*PacketCapture, error) {
fileExists = true fileExists = true
} }
// Open in append mode var file *os.File
file, err := os.OpenFile(outputPath, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0644) if fileExists {
file, err = os.OpenFile(outputPath, os.O_APPEND, 0644)
} else {
file, err = os.Create(outputPath)
}
if err != nil { if err != nil {
handle.Close() handle.Close()
return nil, fmt.Errorf("create/open pcap file: %w", err) return nil, fmt.Errorf("create/open pcap file: %w", err)