fix(bolt): create bolt/data dir if not exist

pull/10616/head
Chris Goller 2018-10-26 16:15:48 -05:00
parent 7bd425a9fe
commit 6f10173a2d
1 changed files with 6 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"time"
"github.com/coreos/bbolt"
@ -64,6 +65,11 @@ func (c *Client) WithTime(fn func() time.Time) {
// Open / create boltDB file.
func (c *Client) Open(ctx context.Context) error {
// Ensure the required directory structure exists.
if err := os.MkdirAll(filepath.Dir(c.Path), 0700); err != nil {
return fmt.Errorf("unable to create directory %s: %v", c.Path, err)
}
if _, err := os.Stat(c.Path); err != nil && !os.IsNotExist(err) {
return err
}