Fix DB.Copy() meta lock and partial write checks.

master
Ben Johnson 2014-03-25 08:48:58 -06:00
parent 2327fd97d7
commit f45f1ed8d4
1 changed files with 12 additions and 1 deletions

13
db.go
View File

@ -453,13 +453,24 @@ func (db *DB) Copy(w io.Writer) error {
return err
}
// Copy everything.
// Copy the meta pages.
db.metalock.Lock()
_, err = io.CopyN(w, f, int64(db.pageSize*2))
db.metalock.Unlock()
if err != nil {
_ = t.Rollback()
_ = f.Close()
return fmt.Errorf("meta copy: %s", err)
}
// Copy data pages.
if _, err := io.Copy(w, f); err != nil {
_ = t.Rollback()
_ = f.Close()
return err
}
// Close read transaction and exit.
if err := t.Rollback(); err != nil {
_ = f.Close()
return err