fix(pcap): try to fix file handle error
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user