diff --git a/cmd/cleanup.go b/cmd/cleanup.go index cac7256e..c225d71f 100644 --- a/cmd/cleanup.go +++ b/cmd/cleanup.go @@ -35,9 +35,9 @@ var cleanupCmd = &cobra.Command{ var cleaned int = 0 // Check if cache dir exists - if helpers.Exists(helpers.GetSystemPkgsCacheDirPath()) { + if helpers.Exists(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath()) { - files, err := ioutil.ReadDir(helpers.GetSystemPkgsCacheDirPath()) + files, err := ioutil.ReadDir(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath()) if err != nil { Fatal("Error on read cachedir ", err.Error()) } @@ -52,7 +52,7 @@ var cleanupCmd = &cobra.Command{ } err := os.RemoveAll( - filepath.Join(helpers.GetSystemPkgsCacheDirPath(), file.Name())) + filepath.Join(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath(), file.Name())) if err != nil { Fatal("Error on removing", file.Name()) } diff --git a/cmd/install.go b/cmd/install.go index 5e7299e4..e06f7f29 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -81,7 +81,7 @@ var installCmd = &cobra.Command{ if LuetCfg.GetSystem().DatabaseEngine == "boltdb" { systemDB = pkg.NewBoltDatabase( - filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db")) + filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db")) } else { systemDB = pkg.NewInMemoryDatabase(true) } diff --git a/cmd/repo/list.go b/cmd/repo/list.go index 1fd8aa48..c8c4b727 100644 --- a/cmd/repo/list.go +++ b/cmd/repo/list.go @@ -23,7 +23,6 @@ import ( "time" . "github.com/mudler/luet/pkg/config" - "github.com/mudler/luet/pkg/helpers" installer "github.com/mudler/luet/pkg/installer" . "github.com/logrusorgru/aurora" @@ -69,7 +68,7 @@ func NewRepoListCommand() *cobra.Command { repoText = Yellow(repo.Urls[0]).String() } - repobasedir := helpers.GetRepoDatabaseDirPath(repo.Name) + repobasedir := LuetCfg.GetSystem().GetRepoDatabaseDirPath(repo.Name) if repo.Cached { r := installer.NewSystemRepository(repo) diff --git a/cmd/search.go b/cmd/search.go index 1c4c649d..df0f2227 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -75,7 +75,7 @@ var searchCmd = &cobra.Command{ if LuetCfg.GetSystem().DatabaseEngine == "boltdb" { systemDB = pkg.NewBoltDatabase( - filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db")) + filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db")) } else { systemDB = pkg.NewInMemoryDatabase(true) } diff --git a/cmd/uninstall.go b/cmd/uninstall.go index f30ac148..2633290e 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -64,7 +64,7 @@ var uninstallCmd = &cobra.Command{ if LuetCfg.GetSystem().DatabaseEngine == "boltdb" { systemDB = pkg.NewBoltDatabase( - filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db")) + filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db")) } else { systemDB = pkg.NewInMemoryDatabase(true) } diff --git a/cmd/upgrade.go b/cmd/upgrade.go index c44b3d0b..ca1dbe52 100644 --- a/cmd/upgrade.go +++ b/cmd/upgrade.go @@ -57,7 +57,7 @@ var upgradeCmd = &cobra.Command{ if LuetCfg.GetSystem().DatabaseEngine == "boltdb" { systemDB = pkg.NewBoltDatabase( - filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db")) + filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db")) } else { systemDB = pkg.NewInMemoryDatabase(true) } diff --git a/pkg/config/config.go b/pkg/config/config.go index 226cba71..4e407f7b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -22,7 +22,12 @@ import ( "os/user" "runtime" "time" + "io/ioutil" + "os" + "path/filepath" + pkg "github.com/mudler/luet/pkg/package" + solver "github.com/mudler/luet/pkg/solver" v "github.com/spf13/viper" ) @@ -51,6 +56,46 @@ type LuetSystemConfig struct { PkgsCachePath string `yaml:"pkgs_cache_path" mapstructure:"pkgs_cache_path"` } + +func (sc LuetSystemConfig) GetRepoDatabaseDirPath(name string) string { + dbpath := filepath.Join(sc.Rootfs, sc.DatabasePath) + dbpath = filepath.Join(dbpath, "repos/"+name) + err := os.MkdirAll(dbpath, os.ModePerm) + if err != nil { + panic(err) + } + return dbpath +} + +func (sc LuetSystemConfig) GetSystemRepoDatabaseDirPath() string { + dbpath := filepath.Join(sc.Rootfs, + sc.DatabasePath) + err := os.MkdirAll(dbpath, os.ModePerm) + if err != nil { + panic(err) + } + return dbpath +} + +func (sc LuetSystemConfig) GetSystemPkgsCacheDirPath() (ans string) { + var cachepath string + if sc.PkgsCachePath != "" { + cachepath = sc.PkgsCachePath + } else { + // Create dynamic cache for test suites + cachepath, _ = ioutil.TempDir(os.TempDir(), "cachepkgs") + } + + if filepath.IsAbs(cachepath) { + ans = cachepath + } else { + ans = filepath.Join(sc.GetSystemRepoDatabaseDirPath(), cachepath) + } + + return +} + + type LuetRepository struct { Name string `json:"name" yaml:"name" mapstructure:"name"` Description string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description"` diff --git a/pkg/helpers/repository.go b/pkg/helpers/repository.go deleted file mode 100644 index 370471d0..00000000 --- a/pkg/helpers/repository.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright © 2019 Ettore Di Giacinto -// Daniele Rondina -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along -// with this program; if not, see . - -package helpers - -import ( - "io/ioutil" - "os" - "path/filepath" - - "github.com/mudler/luet/pkg/config" -) - -func GetRepoDatabaseDirPath(name string) string { - dbpath := filepath.Join(config.LuetCfg.GetSystem().Rootfs, config.LuetCfg.GetSystem().DatabasePath) - dbpath = filepath.Join(dbpath, "repos/"+name) - err := os.MkdirAll(dbpath, os.ModePerm) - if err != nil { - panic(err) - } - return dbpath -} - -func GetSystemRepoDatabaseDirPath() string { - dbpath := filepath.Join(config.LuetCfg.GetSystem().Rootfs, - config.LuetCfg.GetSystem().DatabasePath) - err := os.MkdirAll(dbpath, os.ModePerm) - if err != nil { - panic(err) - } - return dbpath -} - -func GetSystemPkgsCacheDirPath() (ans string) { - var cachepath string - if config.LuetCfg.GetSystem().PkgsCachePath != "" { - cachepath = config.LuetCfg.GetSystem().PkgsCachePath - } else { - // Create dynamic cache for test suites - cachepath, _ = ioutil.TempDir(os.TempDir(), "cachepkgs") - } - - if filepath.IsAbs(cachepath) { - ans = cachepath - } else { - ans = filepath.Join(GetSystemRepoDatabaseDirPath(), cachepath) - } - - return -} diff --git a/pkg/installer/client/http.go b/pkg/installer/client/http.go index 95dae4bd..7afa3c12 100644 --- a/pkg/installer/client/http.go +++ b/pkg/installer/client/http.go @@ -28,6 +28,7 @@ import ( "github.com/mudler/luet/pkg/compiler" "github.com/mudler/luet/pkg/helpers" + "github.com/mudler/luet/pkg/config" "github.com/cavaliercoder/grab" ) @@ -70,7 +71,7 @@ func (c *HttpClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Arti var temp string artifactName := path.Base(artifact.GetPath()) - cacheFile := filepath.Join(helpers.GetSystemPkgsCacheDirPath(), artifactName) + cacheFile := filepath.Join(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath(), artifactName) ok := false // Check if file is already in cache diff --git a/pkg/installer/client/local.go b/pkg/installer/client/local.go index 62799dbe..d85f4722 100644 --- a/pkg/installer/client/local.go +++ b/pkg/installer/client/local.go @@ -22,6 +22,7 @@ import ( "path/filepath" . "github.com/mudler/luet/pkg/logger" + "github.com/mudler/luet/pkg/config" "github.com/mudler/luet/pkg/compiler" "github.com/mudler/luet/pkg/helpers" @@ -39,7 +40,7 @@ func (c *LocalClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Art var err error artifactName := path.Base(artifact.GetPath()) - cacheFile := filepath.Join(helpers.GetSystemPkgsCacheDirPath(), artifactName) + cacheFile := filepath.Join(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath(), artifactName) // Check if file is already in cache if helpers.Exists(cacheFile) { diff --git a/pkg/installer/installer.go b/pkg/installer/installer.go index 043469b6..1028f9bc 100644 --- a/pkg/installer/installer.go +++ b/pkg/installer/installer.go @@ -25,6 +25,7 @@ import ( "github.com/ghodss/yaml" compiler "github.com/mudler/luet/pkg/compiler" + "github.com/mudler/luet/pkg/config" "github.com/mudler/luet/pkg/helpers" . "github.com/mudler/luet/pkg/logger" pkg "github.com/mudler/luet/pkg/package" diff --git a/pkg/installer/repository.go b/pkg/installer/repository.go index 22eebde2..2b7eb009 100644 --- a/pkg/installer/repository.go +++ b/pkg/installer/repository.go @@ -360,7 +360,7 @@ func (r *LuetSystemRepository) Sync(force bool) (Repository, error) { return nil, errors.Wrap(err, "While downloading "+REPOSITORY_SPECFILE) } - repobasedir := helpers.GetRepoDatabaseDirPath(r.GetName()) + repobasedir := config.LuetCfg.GetSystem().GetRepoDatabaseDirPath(r.GetName()) repo, err := r.ReadSpecFile(file, false) if err != nil { return nil, err