mirror of
https://github.com/mudler/luet.git
synced 2025-09-16 23:31:08 +00:00
Allow to set db/rootfs from CLI in cleanup
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
. "github.com/mudler/luet/pkg/config"
|
||||||
config "github.com/mudler/luet/pkg/config"
|
config "github.com/mudler/luet/pkg/config"
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
@@ -31,13 +32,24 @@ var cleanupCmd = &cobra.Command{
|
|||||||
Use: "cleanup",
|
Use: "cleanup",
|
||||||
Short: "Clean packages cache.",
|
Short: "Clean packages cache.",
|
||||||
Long: `remove downloaded packages tarballs and clean cache directory`,
|
Long: `remove downloaded packages tarballs and clean cache directory`,
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
LuetCfg.Viper.BindPFlag("system.database_path", cmd.Flags().Lookup("system-dbpath"))
|
||||||
|
LuetCfg.Viper.BindPFlag("system.rootfs", cmd.Flags().Lookup("system-target"))
|
||||||
|
LuetCfg.Viper.BindPFlag("installed", cmd.Flags().Lookup("installed"))
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var cleaned int = 0
|
var cleaned int = 0
|
||||||
|
dbpath := LuetCfg.Viper.GetString("system.database_path")
|
||||||
|
rootfs := config.LuetCfg.Viper.GetString("system.rootfs")
|
||||||
|
engine := config.LuetCfg.Viper.GetString("system.database_engine")
|
||||||
|
|
||||||
|
LuetCfg.System.DatabaseEngine = engine
|
||||||
|
LuetCfg.System.DatabasePath = dbpath
|
||||||
|
LuetCfg.System.Rootfs = rootfs
|
||||||
// Check if cache dir exists
|
// Check if cache dir exists
|
||||||
if helpers.Exists(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath()) {
|
if helpers.Exists(LuetCfg.GetSystem().GetSystemPkgsCacheDirPath()) {
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath())
|
files, err := ioutil.ReadDir(LuetCfg.GetSystem().GetSystemPkgsCacheDirPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error on read cachedir ", err.Error())
|
Fatal("Error on read cachedir ", err.Error())
|
||||||
}
|
}
|
||||||
@@ -47,12 +59,12 @@ var cleanupCmd = &cobra.Command{
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.LuetCfg.GetGeneral().Debug {
|
if LuetCfg.GetGeneral().Debug {
|
||||||
Info("Removing ", file.Name())
|
Info("Removing ", file.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.RemoveAll(
|
err := os.RemoveAll(
|
||||||
filepath.Join(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath(), file.Name()))
|
filepath.Join(LuetCfg.GetSystem().GetSystemPkgsCacheDirPath(), file.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error on removing", file.Name())
|
Fatal("Error on removing", file.Name())
|
||||||
}
|
}
|
||||||
@@ -66,5 +78,8 @@ var cleanupCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
cleanupCmd.Flags().String("system-dbpath", "", "System db path")
|
||||||
|
cleanupCmd.Flags().String("system-target", "", "System rootpath")
|
||||||
|
cleanupCmd.Flags().String("system-engine", "", "System DB engine")
|
||||||
RootCmd.AddCommand(cleanupCmd)
|
RootCmd.AddCommand(cleanupCmd)
|
||||||
}
|
}
|
||||||
|
@@ -73,7 +73,7 @@ testInstall2() {
|
|||||||
luet install -y --config $tmpdir/luet.yaml --system-target $tmpdir/foo test/c
|
luet install -y --config $tmpdir/luet.yaml --system-target $tmpdir/foo test/c
|
||||||
installst=$?
|
installst=$?
|
||||||
assertEquals 'install test successfully' "$installst" "0"
|
assertEquals 'install test successfully' "$installst" "0"
|
||||||
assertTrue 'db not created' "[ ! -e '$tmpdir/foo/var/luetdb' ]"
|
assertTrue 'db not created' "[ ! -e '$tmpdir/foo/var/cache/luet/luet.db' ]"
|
||||||
assertTrue 'package installed' "[ -e '$tmpdir/foo/c' ]"
|
assertTrue 'package installed' "[ -e '$tmpdir/foo/c' ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ testInstall4() {
|
|||||||
installst=$?
|
installst=$?
|
||||||
assertEquals 'install test successfully' "$installst" "0"
|
assertEquals 'install test successfully' "$installst" "0"
|
||||||
assertTrue 'package installed' "[ -e '$tmpdir/bad/c' ]"
|
assertTrue 'package installed' "[ -e '$tmpdir/bad/c' ]"
|
||||||
assertTrue 'db created' "[ -d '$tmpdir/bad/var/luetdb' ]"
|
assertTrue 'db created' "[ -d '$tmpdir/bad/var/cache/luet' ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
testCleanup4() {
|
testCleanup4() {
|
||||||
|
Reference in New Issue
Block a user