From 5d1dd6657a1e423ee6148a8fd5fbaee1f18a9627 Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Wed, 7 Aug 2019 21:47:51 +1000 Subject: [PATCH] Fixed handling of missing config.json from cli behavior --- bitcask.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bitcask.go b/bitcask.go index 66a3ffb..625193b 100644 --- a/bitcask.go +++ b/bitcask.go @@ -11,8 +11,8 @@ import ( "path/filepath" "sync" - "github.com/gofrs/flock" "github.com/derekparker/trie" + "github.com/gofrs/flock" "github.com/prologic/bitcask/internal" ) @@ -430,18 +430,23 @@ func (b *Bitcask) Merge() error { // Options can be provided with the `WithXXX` functions that provide // configuration options as functions. func Open(path string, options ...Option) (*Bitcask, error) { + var ( + cfg *config + err error + ) + if err := os.MkdirAll(path, 0755); err != nil { return nil, err } - config, err := getConfig(path) + cfg, err = getConfig(path) if err != nil { - return nil, err + cfg = newDefaultConfig() } bitcask := &Bitcask{ Flock: flock.New(filepath.Join(path, "lock")), - config: config, + config: cfg, options: options, path: path, }