mirror of https://github.com/hak5/bolt.git
Fix DB.Copy() meta lock and partial write checks.
parent
2327fd97d7
commit
f45f1ed8d4
13
db.go
13
db.go
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue