diff options
| author | John R. Lenton <jlenton@gmail.com> | 2018-01-04 17:36:42 +0000 |
|---|---|---|
| committer | John R. Lenton <jlenton@gmail.com> | 2018-01-04 17:36:42 +0000 |
| commit | 2091a995d48cdf05f18e245a7d1218ed0a359a3d (patch) | |
| tree | 2a6e5fc6752da52a858fc9054f0e3b6aed6e5376 /advisor | |
| parent | 1073dd5f29532b373b730050803e087950a88478 (diff) | |
typo, and reviewe feedback (thanks mvo)
Diffstat (limited to 'advisor')
| -rw-r--r-- | advisor/backend.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/advisor/backend.go b/advisor/backend.go index 9e75b746ca..d14d9bc4b9 100644 --- a/advisor/backend.go +++ b/advisor/backend.go @@ -31,18 +31,20 @@ import ( var cmdBucketKey = []byte("Commands") type writer struct { - db *bolt.DB - tx *bolt.Tx - b *bolt.Bucket + db *bolt.DB + tx *bolt.Tx + bucket *bolt.Bucket } type CommandDB interface { // AddSnap adds the entries for commands pointing to the given // snap name to the commands database. AddSnap(snapName string, commands []string) error - // Commit persist the changes, and closes the database. + // Commit persist the changes, and closes the database. If the + // database has already been committed/rollbacked, does nothing. Commit() error - // Rollback aborts the changes, and closes teh database. + // Rollback aborts the changes, and closes the database. If the + // database has already been committed/rollbacked, does nothing. Rollback() error } @@ -64,7 +66,7 @@ func Create() (CommandDB, error) { if err == nil { err = t.tx.DeleteBucket(cmdBucketKey) if err == nil || err == bolt.ErrBucketNotFound { - t.b, err = t.tx.CreateBucket(cmdBucketKey) + t.bucket, err = t.tx.CreateBucket(cmdBucketKey) } if err != nil { t.tx.Rollback() @@ -84,13 +86,13 @@ func (t *writer) AddSnap(snapName string, commands []string) error { for _, cmd := range commands { bcmd := []byte(cmd) - row := t.b.Get(bcmd) + row := t.bucket.Get(bcmd) if row == nil { row = bname } else { row = append(append(row, ','), bname...) } - if err := t.b.Put(bcmd, row); err != nil { + if err := t.bucket.Put(bcmd, row); err != nil { return err } } @@ -109,7 +111,7 @@ func (t *writer) Rollback() error { func (t *writer) done(commit bool) error { var e1, e2 error - t.b = nil + t.bucket = nil if t.tx != nil { if commit { e1 = t.tx.Commit() |
