From ebe7466fdcd163cbb8f84a8e47868f60411113f9 Mon Sep 17 00:00:00 2001 From: Daniele Rondina Date: Sat, 7 Nov 2020 18:28:23 +0100 Subject: [PATCH] Respect rootfs path for load config --- pkg/config/config.go | 10 +++++++--- pkg/installer/config_protect.go | 9 +++++++++ pkg/repository/loader.go | 10 ++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 9d5131e4..c4e1f217 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -97,7 +97,7 @@ type LuetSystemConfig struct { 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(dbpath, "repos/"+name) err := os.MkdirAll(dbpath, os.ModePerm) @@ -107,7 +107,7 @@ func (sc LuetSystemConfig) GetRepoDatabaseDirPath(name string) string { return dbpath } -func (sc LuetSystemConfig) GetSystemRepoDatabaseDirPath() string { +func (sc *LuetSystemConfig) GetSystemRepoDatabaseDirPath() string { dbpath := filepath.Join(sc.Rootfs, sc.DatabasePath) err := os.MkdirAll(dbpath, os.ModePerm) @@ -117,7 +117,7 @@ func (sc LuetSystemConfig) GetSystemRepoDatabaseDirPath() string { return dbpath } -func (sc LuetSystemConfig) GetSystemPkgsCacheDirPath() (ans string) { +func (sc *LuetSystemConfig) GetSystemPkgsCacheDirPath() (ans string) { var cachepath string if sc.PkgsCachePath != "" { cachepath = sc.PkgsCachePath @@ -135,6 +135,10 @@ func (sc LuetSystemConfig) GetSystemPkgsCacheDirPath() (ans string) { return } +func (sc *LuetSystemConfig) GetRootFsAbs() (string, error) { + return filepath.Abs(sc.Rootfs) +} + 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/installer/config_protect.go b/pkg/installer/config_protect.go index 88de742b..42ebe69d 100644 --- a/pkg/installer/config_protect.go +++ b/pkg/installer/config_protect.go @@ -19,6 +19,7 @@ package installer import ( "io/ioutil" "path" + "path/filepath" "regexp" "github.com/ghodss/yaml" @@ -30,7 +31,15 @@ import ( func LoadConfigProtectConfs(c *LuetConfig) error { 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 { + cdir = filepath.Join(rootfs, cdir) + Debug("Parsing Config Protect Directory", cdir, "...") files, err := ioutil.ReadDir(cdir) diff --git a/pkg/repository/loader.go b/pkg/repository/loader.go index 2f3a0d7e..08b5c018 100644 --- a/pkg/repository/loader.go +++ b/pkg/repository/loader.go @@ -19,6 +19,7 @@ package repository import ( "io/ioutil" "path" + "path/filepath" "regexp" "github.com/ghodss/yaml" @@ -30,7 +31,16 @@ import ( func LoadRepositories(c *LuetConfig) error { 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 { + + rdir = filepath.Join(rootfs, rdir) + Debug("Parsing Repository Directory", rdir, "...") files, err := ioutil.ReadDir(rdir)