From 87b7bed513c5a5cd2f11ce5595a259d556d9bb58 Mon Sep 17 00:00:00 2001 From: cmasone-attic Date: Thu, 5 Jan 2017 11:51:56 -0800 Subject: [PATCH] NBS: Create directory for store if it doesn't exist (#3028) Fixes #2909 --- go/nbs/block_store_test.go | 15 +++++++++++++-- go/nbs/store.go | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/go/nbs/block_store_test.go b/go/nbs/block_store_test.go index a3d357853d..6e02c4ff98 100644 --- a/go/nbs/block_store_test.go +++ b/go/nbs/block_store_test.go @@ -9,6 +9,7 @@ import ( "crypto/rand" "io/ioutil" "os" + "path/filepath" "sort" "testing" @@ -43,12 +44,22 @@ func (suite *BlockStoreSuite) SetupTest() { func (suite *BlockStoreSuite) TearDownTest() { suite.store.Close() - os.Remove(suite.dir) + os.RemoveAll(suite.dir) +} + +func (suite *BlockStoreSuite) TestChunkStoreMkdir() { + newDir := filepath.Join(suite.dir, "newthing") + store := NewLocalStore(newDir, testMemTableSize) + + c := chunks.NewChunk([]byte("abc")) + suite.store.Put(c) + + suite.NotPanics(func() { store.UpdateRoot(c.Hash(), store.Root()) }) } func (suite *BlockStoreSuite) TestChunkStorePut() { input := []byte("abc") - c := chunks.NewChunk([]byte(input)) + c := chunks.NewChunk(input) suite.store.Put(c) h := c.Hash() diff --git a/go/nbs/store.go b/go/nbs/store.go index d5083b8382..c246286a13 100644 --- a/go/nbs/store.go +++ b/go/nbs/store.go @@ -5,6 +5,7 @@ package nbs import ( + "os" "sort" "sync" @@ -81,6 +82,8 @@ func newAWSStore(table, ns, bucket string, sess *session.Session, memTableSize u } func NewLocalStore(dir string, memTableSize uint64) *NomsBlockStore { + err := os.MkdirAll(dir, 0777) + d.PanicIfError(err) return newNomsBlockStore(fileManifest{dir}, newFSTableSet(dir), memTableSize) }