Refactor: get systemdb from config, which knows which one to load

This commit is contained in:
Ettore Di Giacinto
2020-12-19 17:23:59 +01:00
parent 96e877fc0b
commit e52bc4f2b2
9 changed files with 19 additions and 77 deletions

View File

@@ -17,7 +17,6 @@ package cmd_database
import (
"io/ioutil"
"path/filepath"
"github.com/mudler/luet/pkg/compiler"
. "github.com/mudler/luet/pkg/logger"
@@ -51,7 +50,7 @@ For reference, inspect a "metadata.yaml" file generated while running "luet buil
},
Run: func(cmd *cobra.Command, args []string) {
var systemDB pkg.PackageDatabase
systemDB := LuetCfg.GetSystemDB()
for _, a := range args {
dat, err := ioutil.ReadFile(a)
@@ -63,13 +62,6 @@ For reference, inspect a "metadata.yaml" file generated while running "luet buil
Fatal("Failed reading yaml ", a, ": ", err.Error())
}
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
systemDB = pkg.NewBoltDatabase(
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
} else {
systemDB = pkg.NewInMemoryDatabase(true)
}
files := art.GetFiles()
if _, err := systemDB.CreatePackage(art.GetCompileSpec().GetPackage()); err != nil {

View File

@@ -16,13 +16,10 @@
package cmd_database
import (
"path/filepath"
. "github.com/mudler/luet/pkg/logger"
helpers "github.com/mudler/luet/cmd/helpers"
. "github.com/mudler/luet/pkg/config"
pkg "github.com/mudler/luet/pkg/package"
"github.com/spf13/cobra"
)
@@ -44,7 +41,7 @@ This commands takes multiple packages as arguments and prunes their entries from
},
Run: func(cmd *cobra.Command, args []string) {
var systemDB pkg.PackageDatabase
systemDB := LuetCfg.GetSystemDB()
for _, a := range args {
pack, err := helpers.ParsePackageStr(a)
@@ -52,13 +49,6 @@ This commands takes multiple packages as arguments and prunes their entries from
Fatal("Invalid package string ", a, ": ", err.Error())
}
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
systemDB = pkg.NewBoltDatabase(
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
} else {
systemDB = pkg.NewInMemoryDatabase(true)
}
if err := systemDB.RemovePackage(pack); err != nil {
Fatal("Failed removing ", a, ": ", err.Error())
}