fix: resolve bugs found in pre-release review
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
bolt "go.etcd.io/bbolt"
|
||||
bolterrors "go.etcd.io/bbolt/errors"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
@@ -12,8 +15,11 @@ type Store struct {
|
||||
}
|
||||
|
||||
func Open(dir string) (*Store, error) {
|
||||
db, err := bolt.Open(filepath.Join(dir, ".tracks.db"), 0600, nil)
|
||||
db, err := bolt.Open(filepath.Join(dir, ".tracks.db"), 0600, &bolt.Options{Timeout: 5 * time.Second})
|
||||
if err != nil {
|
||||
if errors.Is(err, bolterrors.ErrTimeout) {
|
||||
return nil, fmt.Errorf("database is already in use by another process")
|
||||
}
|
||||
return nil, fmt.Errorf("failed to open database: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user