Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions extractor/trap/trapwriter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package trap

import (
"bufio"
"errors"
"fmt"
"go/types"
Expand All @@ -15,7 +16,8 @@ import (

// A Writer provides methods for writing data to a TRAP file
type Writer struct {
w *os.File
w *bufio.Writer
file *os.File
Labeler *Labeler
path string
trapFilePath string
Expand All @@ -40,6 +42,7 @@ func NewWriter(path string, pkg *packages.Package) (*Writer, error) {
return nil, err
}
tw := &Writer{
bufio.NewWriter(tmpFile),
tmpFile,
nil,
path,
Expand Down Expand Up @@ -67,15 +70,15 @@ func trapFolder() (string, error) {

// Close the underlying file writer
func (tw *Writer) Close() error {
err := tw.w.Sync()
err := tw.w.Flush()
if err != nil {
return err
}
err = tw.w.Close()
err = tw.file.Close()
if err != nil {
return err
}
return os.Rename(tw.w.Name(), tw.trapFilePath)
return os.Rename(tw.file.Name(), tw.trapFilePath)
}

// ForEachObject iterates over all objects labeled by this labeler, and invokes
Expand Down