multi: specify DB filename when opening clientdb

To make it possible to open any DB in the debug CLI, we allow specifying
the file name too instead of only the path.
This commit is contained in:
Oliver Gugger 2020-11-24 11:18:24 +01:00
parent 394c6c1747
commit 9714deb848
No known key found for this signature in database
GPG key ID: 8E4256593F177720
4 changed files with 7 additions and 7 deletions

View file

@ -51,7 +51,7 @@ func newTestDB(t *testing.T) (*DB, func()) {
t.Fatalf("unable to create temp dir: %v", err)
}
db, err := New(tempDir)
db, err := New(tempDir, DBFilename)
if err != nil {
os.RemoveAll(tempDir)
t.Fatalf("unable to create new db: %v", err)

View file

@ -9,8 +9,8 @@ import (
)
const (
// dbFilename is the default filename of the client database.
dbFilename = "pool.db"
// DBFilename is the default filename of the client database.
DBFilename = "pool.db"
// dbFilePermission is the default permission the client database file
// is created with.
@ -29,9 +29,9 @@ type DB struct {
}
// New creates a new bolt database that can be found at the given directory.
func New(dir string) (*DB, error) {
func New(dir, fileName string) (*DB, error) {
firstInit := false
path := filepath.Join(dir, dbFilename)
path := filepath.Join(dir, fileName)
// If the database file does not exist yet, create its directory.
if !fileExists(path) {

View file

@ -199,7 +199,7 @@ func newManagerHarness(t *testing.T) *managerHarness {
tempDir, err := ioutil.TempDir("", "client-db")
require.NoError(t, err)
db, err := clientdb.New(tempDir)
db, err := clientdb.New(tempDir, clientdb.DBFilename)
if err != nil {
_ = os.RemoveAll(tempDir)
t.Fatalf("unable to create new db: %v", err)

View file

@ -378,7 +378,7 @@ func (s *Server) setupClient() error {
// Open the main database.
var err error
s.db, err = clientdb.New(s.cfg.BaseDir)
s.db, err = clientdb.New(s.cfg.BaseDir, clientdb.DBFilename)
if err != nil {
return err
}