mirror of
https://github.com/mudler/luet.git
synced 2025-08-10 03:37:28 +00:00
Move repository helpers under config
They are generated after the system config, let the structure provide such information
This commit is contained in:
parent
4f33eca263
commit
dfb6dab9dc
@ -35,9 +35,9 @@ var cleanupCmd = &cobra.Command{
|
|||||||
var cleaned int = 0
|
var cleaned int = 0
|
||||||
|
|
||||||
// Check if cache dir exists
|
// 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 {
|
if err != nil {
|
||||||
Fatal("Error on read cachedir ", err.Error())
|
Fatal("Error on read cachedir ", err.Error())
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ var cleanupCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
err := os.RemoveAll(
|
err := os.RemoveAll(
|
||||||
filepath.Join(helpers.GetSystemPkgsCacheDirPath(), file.Name()))
|
filepath.Join(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath(), file.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal("Error on removing", file.Name())
|
Fatal("Error on removing", file.Name())
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ var installCmd = &cobra.Command{
|
|||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
||||||
systemDB = pkg.NewBoltDatabase(
|
systemDB = pkg.NewBoltDatabase(
|
||||||
filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db"))
|
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
||||||
} else {
|
} else {
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
systemDB = pkg.NewInMemoryDatabase(true)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/mudler/luet/pkg/config"
|
. "github.com/mudler/luet/pkg/config"
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
|
||||||
installer "github.com/mudler/luet/pkg/installer"
|
installer "github.com/mudler/luet/pkg/installer"
|
||||||
|
|
||||||
. "github.com/logrusorgru/aurora"
|
. "github.com/logrusorgru/aurora"
|
||||||
@ -69,7 +68,7 @@ func NewRepoListCommand() *cobra.Command {
|
|||||||
repoText = Yellow(repo.Urls[0]).String()
|
repoText = Yellow(repo.Urls[0]).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
repobasedir := helpers.GetRepoDatabaseDirPath(repo.Name)
|
repobasedir := LuetCfg.GetSystem().GetRepoDatabaseDirPath(repo.Name)
|
||||||
if repo.Cached {
|
if repo.Cached {
|
||||||
|
|
||||||
r := installer.NewSystemRepository(repo)
|
r := installer.NewSystemRepository(repo)
|
||||||
|
@ -75,7 +75,7 @@ var searchCmd = &cobra.Command{
|
|||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
||||||
systemDB = pkg.NewBoltDatabase(
|
systemDB = pkg.NewBoltDatabase(
|
||||||
filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db"))
|
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
||||||
} else {
|
} else {
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
systemDB = pkg.NewInMemoryDatabase(true)
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ var uninstallCmd = &cobra.Command{
|
|||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
||||||
systemDB = pkg.NewBoltDatabase(
|
systemDB = pkg.NewBoltDatabase(
|
||||||
filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db"))
|
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
||||||
} else {
|
} else {
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
systemDB = pkg.NewInMemoryDatabase(true)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ var upgradeCmd = &cobra.Command{
|
|||||||
|
|
||||||
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
if LuetCfg.GetSystem().DatabaseEngine == "boltdb" {
|
||||||
systemDB = pkg.NewBoltDatabase(
|
systemDB = pkg.NewBoltDatabase(
|
||||||
filepath.Join(helpers.GetSystemRepoDatabaseDirPath(), "luet.db"))
|
filepath.Join(LuetCfg.GetSystem().GetSystemRepoDatabaseDirPath(), "luet.db"))
|
||||||
} else {
|
} else {
|
||||||
systemDB = pkg.NewInMemoryDatabase(true)
|
systemDB = pkg.NewInMemoryDatabase(true)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,12 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"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"
|
v "github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,6 +56,46 @@ type LuetSystemConfig struct {
|
|||||||
PkgsCachePath string `yaml:"pkgs_cache_path" mapstructure:"pkgs_cache_path"`
|
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 {
|
type LuetRepository struct {
|
||||||
Name string `json:"name" yaml:"name" mapstructure:"name"`
|
Name string `json:"name" yaml:"name" mapstructure:"name"`
|
||||||
Description string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description"`
|
Description string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description"`
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
||||||
// Daniele Rondina <geaaru@sabayonlinux.org>
|
|
||||||
//
|
|
||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
@ -28,6 +28,7 @@ import (
|
|||||||
|
|
||||||
"github.com/mudler/luet/pkg/compiler"
|
"github.com/mudler/luet/pkg/compiler"
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
|
"github.com/mudler/luet/pkg/config"
|
||||||
|
|
||||||
"github.com/cavaliercoder/grab"
|
"github.com/cavaliercoder/grab"
|
||||||
)
|
)
|
||||||
@ -70,7 +71,7 @@ func (c *HttpClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Arti
|
|||||||
var temp string
|
var temp string
|
||||||
|
|
||||||
artifactName := path.Base(artifact.GetPath())
|
artifactName := path.Base(artifact.GetPath())
|
||||||
cacheFile := filepath.Join(helpers.GetSystemPkgsCacheDirPath(), artifactName)
|
cacheFile := filepath.Join(config.LuetCfg.GetSystem().GetSystemPkgsCacheDirPath(), artifactName)
|
||||||
ok := false
|
ok := false
|
||||||
|
|
||||||
// Check if file is already in cache
|
// Check if file is already in cache
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
|
"github.com/mudler/luet/pkg/config"
|
||||||
|
|
||||||
"github.com/mudler/luet/pkg/compiler"
|
"github.com/mudler/luet/pkg/compiler"
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
@ -39,7 +40,7 @@ func (c *LocalClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Art
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
artifactName := path.Base(artifact.GetPath())
|
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
|
// Check if file is already in cache
|
||||||
if helpers.Exists(cacheFile) {
|
if helpers.Exists(cacheFile) {
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
compiler "github.com/mudler/luet/pkg/compiler"
|
compiler "github.com/mudler/luet/pkg/compiler"
|
||||||
|
"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"
|
||||||
pkg "github.com/mudler/luet/pkg/package"
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
|
@ -360,7 +360,7 @@ func (r *LuetSystemRepository) Sync(force bool) (Repository, error) {
|
|||||||
return nil, errors.Wrap(err, "While downloading "+REPOSITORY_SPECFILE)
|
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)
|
repo, err := r.ReadSpecFile(file, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user