Respect rootfs path for load config

This commit is contained in:
Daniele Rondina
2020-11-07 18:28:23 +01:00
parent 76328176c1
commit ebe7466fdc
3 changed files with 26 additions and 3 deletions

View File

@@ -97,7 +97,7 @@ type LuetSystemConfig struct {
TmpDirBase string `yaml:"tmpdir_base" mapstructure:"tmpdir_base"` TmpDirBase string `yaml:"tmpdir_base" mapstructure:"tmpdir_base"`
} }
func (sc LuetSystemConfig) GetRepoDatabaseDirPath(name string) string { func (sc *LuetSystemConfig) GetRepoDatabaseDirPath(name string) string {
dbpath := filepath.Join(sc.Rootfs, sc.DatabasePath) dbpath := filepath.Join(sc.Rootfs, sc.DatabasePath)
dbpath = filepath.Join(dbpath, "repos/"+name) dbpath = filepath.Join(dbpath, "repos/"+name)
err := os.MkdirAll(dbpath, os.ModePerm) err := os.MkdirAll(dbpath, os.ModePerm)
@@ -107,7 +107,7 @@ func (sc LuetSystemConfig) GetRepoDatabaseDirPath(name string) string {
return dbpath return dbpath
} }
func (sc LuetSystemConfig) GetSystemRepoDatabaseDirPath() string { func (sc *LuetSystemConfig) GetSystemRepoDatabaseDirPath() string {
dbpath := filepath.Join(sc.Rootfs, dbpath := filepath.Join(sc.Rootfs,
sc.DatabasePath) sc.DatabasePath)
err := os.MkdirAll(dbpath, os.ModePerm) err := os.MkdirAll(dbpath, os.ModePerm)
@@ -117,7 +117,7 @@ func (sc LuetSystemConfig) GetSystemRepoDatabaseDirPath() string {
return dbpath return dbpath
} }
func (sc LuetSystemConfig) GetSystemPkgsCacheDirPath() (ans string) { func (sc *LuetSystemConfig) GetSystemPkgsCacheDirPath() (ans string) {
var cachepath string var cachepath string
if sc.PkgsCachePath != "" { if sc.PkgsCachePath != "" {
cachepath = sc.PkgsCachePath cachepath = sc.PkgsCachePath
@@ -135,6 +135,10 @@ func (sc LuetSystemConfig) GetSystemPkgsCacheDirPath() (ans string) {
return return
} }
func (sc *LuetSystemConfig) GetRootFsAbs() (string, error) {
return filepath.Abs(sc.Rootfs)
}
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"`

View File

@@ -19,6 +19,7 @@ package installer
import ( import (
"io/ioutil" "io/ioutil"
"path" "path"
"path/filepath"
"regexp" "regexp"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
@@ -30,7 +31,15 @@ import (
func LoadConfigProtectConfs(c *LuetConfig) error { func LoadConfigProtectConfs(c *LuetConfig) error {
var regexConfs = regexp.MustCompile(`.yml$`) var regexConfs = regexp.MustCompile(`.yml$`)
// Respect the rootfs param on read repositories
rootfs, err := c.GetSystem().GetRootFsAbs()
if err != nil {
return err
}
for _, cdir := range c.ConfigProtectConfDir { for _, cdir := range c.ConfigProtectConfDir {
cdir = filepath.Join(rootfs, cdir)
Debug("Parsing Config Protect Directory", cdir, "...") Debug("Parsing Config Protect Directory", cdir, "...")
files, err := ioutil.ReadDir(cdir) files, err := ioutil.ReadDir(cdir)

View File

@@ -19,6 +19,7 @@ package repository
import ( import (
"io/ioutil" "io/ioutil"
"path" "path"
"path/filepath"
"regexp" "regexp"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
@@ -30,7 +31,16 @@ import (
func LoadRepositories(c *LuetConfig) error { func LoadRepositories(c *LuetConfig) error {
var regexRepo = regexp.MustCompile(`.yml$|.yaml$`) var regexRepo = regexp.MustCompile(`.yml$|.yaml$`)
// Respect the rootfs param on read repositories
rootfs, err := c.GetSystem().GetRootFsAbs()
if err != nil {
return err
}
for _, rdir := range c.RepositoriesConfDir { for _, rdir := range c.RepositoriesConfDir {
rdir = filepath.Join(rootfs, rdir)
Debug("Parsing Repository Directory", rdir, "...") Debug("Parsing Repository Directory", rdir, "...")
files, err := ioutil.ReadDir(rdir) files, err := ioutil.ReadDir(rdir)