Skip to content

Commit

Permalink
FAB-17157 rm createTempDir method
Browse files Browse the repository at this point in the history
It simply creates a temp dir or panic, and only called at one place
in the same file. It's cleaner if inlined.

Signed-off-by: Jay Guo <guojiannan1101@gmail.com>
  • Loading branch information
guoger authored and denyeart committed Nov 28, 2019
1 parent e939f9c commit c5d4087
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
13 changes: 4 additions & 9 deletions orderer/common/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import (

func createLedgerFactory(conf *config.TopLevel, metricsProvider metrics.Provider) (blockledger.Factory, string, error) {
ld := conf.FileLedger.Location
var err error
if ld == "" {
ld = createTempDir(conf.FileLedger.Prefix)
if ld, err = ioutil.TempDir("", conf.FileLedger.Prefix); err != nil {
logger.Panic("Error creating temp dir:", err)
}
}

logger.Debug("Ledger dir:", ld)
Expand All @@ -29,11 +32,3 @@ func createLedgerFactory(conf *config.TopLevel, metricsProvider metrics.Provider
}
return lf, ld, nil
}

func createTempDir(dirPrefix string) string {
dirPath, err := ioutil.TempDir("", dirPrefix)
if err != nil {
logger.Panic("Error creating temp dir:", err)
}
return dirPath
}
16 changes: 0 additions & 16 deletions orderer/common/server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,3 @@ func TestCreateLedgerFactory(t *testing.T) {
})
}
}

func TestCreateTempDir(t *testing.T) {
t.Run("Good", func(t *testing.T) {
tempDir := createTempDir("foo")
if _, err := os.Stat(tempDir); err != nil {
t.Fatal(err)
}
})

t.Run("Bad", func(t *testing.T) {
assert.Panics(t, func() {
createTempDir("foo/bar")
})
})

}

0 comments on commit c5d4087

Please sign in to comment.