mirror of
https://github.com/mudler/luet.git
synced 2025-06-26 23:39:55 +00:00
Refactor: get systemdb from config, which knows which one to load
This commit is contained in:
parent
96e877fc0b
commit
e52bc4f2b2
@ -17,7 +17,6 @@ package cmd_database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/mudler/luet/pkg/compiler"
|
"github.com/mudler/luet/pkg/compiler"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "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) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
var systemDB pkg.PackageDatabase
|
systemDB := LuetCfg.GetSystemDB()
|
||||||
|
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
dat, err := ioutil.ReadFile(a)
|
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())
|
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()
|
files := art.GetFiles()
|
||||||
|
|
||||||
if _, err := systemDB.CreatePackage(art.GetCompileSpec().GetPackage()); err != nil {
|
if _, err := systemDB.CreatePackage(art.GetCompileSpec().GetPackage()); err != nil {
|
||||||
|
@ -16,13 +16,10 @@
|
|||||||
package cmd_database
|
package cmd_database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
|
|
||||||
helpers "github.com/mudler/luet/cmd/helpers"
|
helpers "github.com/mudler/luet/cmd/helpers"
|
||||||
. "github.com/mudler/luet/pkg/config"
|
. "github.com/mudler/luet/pkg/config"
|
||||||
pkg "github.com/mudler/luet/pkg/package"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"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) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var systemDB pkg.PackageDatabase
|
systemDB := LuetCfg.GetSystemDB()
|
||||||
|
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
pack, err := helpers.ParsePackageStr(a)
|
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())
|
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 {
|
if err := systemDB.RemovePackage(pack); err != nil {
|
||||||
Fatal("Failed removing ", a, ": ", err.Error())
|
Fatal("Failed removing ", a, ": ", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
installer "github.com/mudler/luet/pkg/installer"
|
installer "github.com/mudler/luet/pkg/installer"
|
||||||
"github.com/mudler/luet/pkg/solver"
|
"github.com/mudler/luet/pkg/solver"
|
||||||
@ -63,7 +62,6 @@ To force install a package:
|
|||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var toInstall pkg.Packages
|
var toInstall pkg.Packages
|
||||||
var systemDB pkg.PackageDatabase
|
|
||||||
|
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
pack, err := helpers.ParsePackageStr(a)
|
pack, err := helpers.ParsePackageStr(a)
|
||||||
@ -120,13 +118,7 @@ To force install a package:
|
|||||||
})
|
})
|
||||||
inst.Repositories(repos)
|
inst.Repositories(repos)
|
||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
system := &installer.System{Database: LuetCfg.GetSystemDB(), Target: LuetCfg.GetSystem().Rootfs}
|
||||||
systemDB = pkg.NewBoltDatabase(
|
|
||||||
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
|
||||||
} else {
|
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
|
||||||
}
|
|
||||||
system := &installer.System{Database: systemDB, Target: LuetCfg.GetSystem().Rootfs}
|
|
||||||
err := inst.Install(toInstall, system)
|
err := inst.Install(toInstall, system)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
|
@ -16,13 +16,11 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
installer "github.com/mudler/luet/pkg/installer"
|
installer "github.com/mudler/luet/pkg/installer"
|
||||||
|
|
||||||
. "github.com/mudler/luet/pkg/config"
|
. "github.com/mudler/luet/pkg/config"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
pkg "github.com/mudler/luet/pkg/package"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -42,7 +40,6 @@ var reclaimCmd = &cobra.Command{
|
|||||||
It scans the target file system, and if finds a match with a package available in the repositories, it marks as installed in the system database.
|
It scans the target file system, and if finds a match with a package available in the repositories, it marks as installed in the system database.
|
||||||
`,
|
`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var systemDB pkg.PackageDatabase
|
|
||||||
|
|
||||||
// This shouldn't be necessary, but we need to unmarshal the repositories to a concrete struct, thus we need to port them back to the Repositories type
|
// This shouldn't be necessary, but we need to unmarshal the repositories to a concrete struct, thus we need to port them back to the Repositories type
|
||||||
repos := installer.Repositories{}
|
repos := installer.Repositories{}
|
||||||
@ -65,13 +62,7 @@ It scans the target file system, and if finds a match with a package available i
|
|||||||
})
|
})
|
||||||
inst.Repositories(repos)
|
inst.Repositories(repos)
|
||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
system := &installer.System{Database: LuetCfg.GetSystemDB(), Target: LuetCfg.GetSystem().Rootfs}
|
||||||
systemDB = pkg.NewBoltDatabase(
|
|
||||||
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
|
||||||
} else {
|
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
|
||||||
}
|
|
||||||
system := &installer.System{Database: systemDB, Target: LuetCfg.GetSystem().Rootfs}
|
|
||||||
err := inst.Reclaim(system)
|
err := inst.Reclaim(system)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
|
@ -16,7 +16,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
installer "github.com/mudler/luet/pkg/installer"
|
installer "github.com/mudler/luet/pkg/installer"
|
||||||
"github.com/mudler/luet/pkg/solver"
|
"github.com/mudler/luet/pkg/solver"
|
||||||
@ -54,7 +53,6 @@ var replaceCmd = &cobra.Command{
|
|||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var toUninstall pkg.Packages
|
var toUninstall pkg.Packages
|
||||||
var toAdd pkg.Packages
|
var toAdd pkg.Packages
|
||||||
var systemDB pkg.PackageDatabase
|
|
||||||
|
|
||||||
f := LuetCfg.Viper.GetStringSlice("for")
|
f := LuetCfg.Viper.GetStringSlice("for")
|
||||||
stype := LuetCfg.Viper.GetString("solver.type")
|
stype := LuetCfg.Viper.GetString("solver.type")
|
||||||
@ -120,13 +118,7 @@ var replaceCmd = &cobra.Command{
|
|||||||
})
|
})
|
||||||
inst.Repositories(repos)
|
inst.Repositories(repos)
|
||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
system := &installer.System{Database: LuetCfg.GetSystemDB(), Target: LuetCfg.GetSystem().Rootfs}
|
||||||
systemDB = pkg.NewBoltDatabase(
|
|
||||||
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
|
||||||
} else {
|
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
|
||||||
}
|
|
||||||
system := &installer.System{Database: systemDB, Target: LuetCfg.GetSystem().Rootfs}
|
|
||||||
err := inst.Swap(toUninstall, toAdd, system)
|
err := inst.Swap(toUninstall, toAdd, system)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
|
@ -17,7 +17,6 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
@ -112,7 +111,6 @@ Search can also return results in the terminal in different ways: as terminal ou
|
|||||||
LuetCfg.Viper.BindPFlag("solver.max_attempts", cmd.Flags().Lookup("solver-attempts"))
|
LuetCfg.Viper.BindPFlag("solver.max_attempts", cmd.Flags().Lookup("solver-attempts"))
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var systemDB pkg.PackageDatabase
|
|
||||||
var results Results
|
var results Results
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
Fatal("Wrong number of arguments (expected 1)")
|
Fatal("Wrong number of arguments (expected 1)")
|
||||||
@ -213,13 +211,7 @@ Search can also return results in the terminal in different ways: as terminal ou
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
system := &installer.System{Database: LuetCfg.GetSystemDB(), Target: LuetCfg.GetSystem().Rootfs}
|
||||||
systemDB = pkg.NewBoltDatabase(
|
|
||||||
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
|
||||||
} else {
|
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
|
||||||
}
|
|
||||||
system := &installer.System{Database: systemDB, Target: LuetCfg.GetSystem().Rootfs}
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
iMatches := pkg.Packages{}
|
iMatches := pkg.Packages{}
|
||||||
|
@ -16,7 +16,6 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
helpers "github.com/mudler/luet/cmd/helpers"
|
helpers "github.com/mudler/luet/cmd/helpers"
|
||||||
. "github.com/mudler/luet/pkg/config"
|
. "github.com/mudler/luet/pkg/config"
|
||||||
@ -45,7 +44,6 @@ var uninstallCmd = &cobra.Command{
|
|||||||
LuetCfg.Viper.BindPFlag("yes", cmd.Flags().Lookup("yes"))
|
LuetCfg.Viper.BindPFlag("yes", cmd.Flags().Lookup("yes"))
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var systemDB pkg.PackageDatabase
|
|
||||||
toRemove := []pkg.Package{}
|
toRemove := []pkg.Package{}
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
|
|
||||||
@ -94,13 +92,7 @@ var uninstallCmd = &cobra.Command{
|
|||||||
PreserveSystemEssentialData: true,
|
PreserveSystemEssentialData: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
system := &installer.System{Database: LuetCfg.GetSystemDB(), Target: LuetCfg.GetSystem().Rootfs}
|
||||||
systemDB = pkg.NewBoltDatabase(
|
|
||||||
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
|
||||||
} else {
|
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
|
||||||
}
|
|
||||||
system := &installer.System{Database: systemDB, Target: LuetCfg.GetSystem().Rootfs}
|
|
||||||
|
|
||||||
if err := inst.Uninstall(system, toRemove...); err != nil {
|
if err := inst.Uninstall(system, toRemove...); err != nil {
|
||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
|
@ -16,12 +16,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
. "github.com/mudler/luet/pkg/config"
|
. "github.com/mudler/luet/pkg/config"
|
||||||
installer "github.com/mudler/luet/pkg/installer"
|
installer "github.com/mudler/luet/pkg/installer"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
pkg "github.com/mudler/luet/pkg/package"
|
|
||||||
"github.com/mudler/luet/pkg/solver"
|
"github.com/mudler/luet/pkg/solver"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -43,7 +41,6 @@ var upgradeCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
Long: `Upgrades packages in parallel`,
|
Long: `Upgrades packages in parallel`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var systemDB pkg.PackageDatabase
|
|
||||||
|
|
||||||
repos := installer.Repositories{}
|
repos := installer.Repositories{}
|
||||||
for _, repo := range LuetCfg.SystemRepositories {
|
for _, repo := range LuetCfg.SystemRepositories {
|
||||||
@ -97,14 +94,7 @@ var upgradeCmd = &cobra.Command{
|
|||||||
})
|
})
|
||||||
inst.Repositories(repos)
|
inst.Repositories(repos)
|
||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
system := &installer.System{Database: LuetCfg.GetSystemDB(), Target: LuetCfg.GetSystem().Rootfs}
|
||||||
systemDB = pkg.NewBoltDatabase(
|
|
||||||
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
|
||||||
} else {
|
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
|
||||||
}
|
|
||||||
system := &installer.System{Database: systemDB, Target: LuetCfg.GetSystem().Rootfs}
|
|
||||||
|
|
||||||
if err := inst.Upgrade(system); err != nil {
|
if err := inst.Upgrade(system); err != nil {
|
||||||
Fatal("Error: " + err.Error())
|
Fatal("Error: " + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
solver "github.com/mudler/luet/pkg/solver"
|
solver "github.com/mudler/luet/pkg/solver"
|
||||||
|
|
||||||
v "github.com/spf13/viper"
|
v "github.com/spf13/viper"
|
||||||
@ -276,6 +277,16 @@ func GenDefault(viper *v.Viper) {
|
|||||||
viper.SetDefault("solver.max_attempts", 9000)
|
viper.SetDefault("solver.max_attempts", 9000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *LuetConfig) GetSystemDB() pkg.PackageDatabase {
|
||||||
|
switch LuetCfg.GetSystem().DatabaseEngine {
|
||||||
|
case "boltdb":
|
||||||
|
return pkg.NewBoltDatabase(
|
||||||
|
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
||||||
|
default:
|
||||||
|
return pkg.NewInMemoryDatabase(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *LuetConfig) AddSystemRepository(r LuetRepository) {
|
func (c *LuetConfig) AddSystemRepository(r LuetRepository) {
|
||||||
c.SystemRepositories = append(c.SystemRepositories, r)
|
c.SystemRepositories = append(c.SystemRepositories, r)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user