Skip to content

Commit

Permalink
fix panic in bolt db udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Feb 20, 2019
1 parent d53610c commit c33df81
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions internal/resumer/boltdbresumer/boltdbresumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,30 @@ func (r *Resumer) Write(spec *Spec) error {

func (r *Resumer) WriteInfo(value []byte) error {
return r.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(r.mainBucket)
b := tx.Bucket(r.mainBucket).Bucket(r.subBucket)
if b == nil {
return nil
}
b = b.Bucket(r.subBucket)
return b.Put(infoKey, value)
})
}

func (r *Resumer) WriteBitfield(value []byte) error {
return r.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(r.mainBucket)
b := tx.Bucket(r.mainBucket).Bucket(r.subBucket)
if b == nil {
return nil
}
b = b.Bucket(r.subBucket)
return b.Put(bitfieldKey, value)
})
}

func (r *Resumer) WriteStats(s resumer.Stats) error {
return r.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(r.mainBucket)
b := tx.Bucket(r.mainBucket).Bucket(r.subBucket)
if b == nil {
return nil
}
b = b.Bucket(r.subBucket)
b.Put(bytesDownloadedKey, []byte(strconv.FormatInt(s.BytesDownloaded, 10)))
b.Put(bytesUploadedKey, []byte(strconv.FormatInt(s.BytesUploaded, 10)))
b.Put(bytesWastedKey, []byte(strconv.FormatInt(s.BytesWasted, 10)))
Expand Down

0 comments on commit c33df81

Please sign in to comment.