From 79bb334b9abbd080b93c302d7d501540c8f00627 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Sun, 15 Sep 2013 16:58:02 -0500 Subject: [PATCH] Remove old regression test db in regtest mode. The regression test mode is special in that the 'official' block test suite requires an empty database to work properly. Rather than having to manual go delete it before each test, add code to automatically delete the old regression test database when in regression test mode. --- blockmanager.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/blockmanager.go b/blockmanager.go index 72bca506..2e674053 100644 --- a/blockmanager.go +++ b/blockmanager.go @@ -397,6 +397,34 @@ func newBlockManager(s *server) *blockManager { return &bm } +// removeRegressionDB removes the existing regression test database if running +// in regression test mode and it already exists. +func removeRegressionDB(dbPath string) error { + // Dont do anything if not in regression test mode. + if !cfg.RegressionTest { + return nil + } + + // Remove the old regression test database if it already exists. + fi, err := os.Stat(dbPath) + if err == nil { + log.Infof("[BMGR] Removing regression test database from '%s'", dbPath) + if fi.IsDir() { + err := os.RemoveAll(dbPath) + if err != nil { + return err + } + } else { + err := os.Remove(dbPath) + if err != nil { + return err + } + } + } + + return nil +} + // loadBlockDB opens the block database and returns a handle to it. func loadBlockDB() (btcdb.Db, error) { // The database name is based on the database type. @@ -406,6 +434,10 @@ func loadBlockDB() (btcdb.Db, error) { } dbPath := filepath.Join(cfg.DataDir, dbName) + // The regression test is special in that it needs a clean database for + // each run, so remove it now if it already exists. + removeRegressionDB(dbPath) + log.Infof("[BMGR] Loading block database from '%s'", dbPath) db, err := btcdb.OpenDB(cfg.DbType, dbPath) if err != nil {