Skip to content

Commit

Permalink
Merge pull request #44 from lorneli/bbolt_tx
Browse files Browse the repository at this point in the history
tx: just close file once in WriteTo function
  • Loading branch information
Anthony Romano committed Sep 14, 2017
2 parents fb37144 + 53a930f commit 2760028
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ func (tx *Tx) WriteTo(w io.Writer) (n int64, err error) {
if err != nil {
return 0, err
}
defer func() { _ = f.Close() }()
defer func() {
if cerr := f.Close(); err == nil {
err = cerr
}
}()

// Generate a meta page. We use the same page data for both meta pages.
buf := make([]byte, tx.db.pageSize)
Expand Down Expand Up @@ -356,7 +360,7 @@ func (tx *Tx) WriteTo(w io.Writer) (n int64, err error) {
return n, err
}

return n, f.Close()
return n, nil
}

// CopyFile copies the entire database to file at the given path.
Expand Down

0 comments on commit 2760028

Please sign in to comment.