tx: just close file once in WriteTo function

WriteTo function closes file twice in normal path previously.
pull/44/head
lorneli 2017-09-11 20:41:08 +08:00
parent 4ff482b44e
commit 53a930f1e1
1 changed files with 6 additions and 2 deletions

8
tx.go
View File

@ -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)
@ -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.