config: Add new functionality to LoadDefaults

This patch adds a couple new features for LoadDefaults().

First, it introduces LoadDefaultsForPath(), which allows the default
values to be set base on a given path instead of always assuming $PWD.

It also removes the restriction that only allowed defaults to be set
when --new-config set was declared. Removing this restriction ensures
that there are always sane parameters available, even if none exists
in the config file.

Lastly, it moves the check for local RPMs to LoadDefaults from
CreateDefaultConfig(). This prevents GetWd() to be called twice and also
allows LOCAL_REPO_DIR and LOCAL_RPM_DIR to be set in the same call.

Signed-off-by: Rodrigo Chiossi <rodrigo.chiossi@intel.com>
This commit is contained in:
Rodrigo Chiossi
2018-05-29 13:33:08 -07:00
committed by tmarcu
parent 90c874af2e
commit b06fa293bf
2 changed files with 22 additions and 25 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ func New() *Builder {
// NewFromConfig creates a new Builder with the given Configuration.
func NewFromConfig(conf string) (*Builder, error) {
b := New()
if err := b.Config.LoadDefaults(); err != nil {
if err := b.Config.LoadDefaults(false); err != nil {
return nil, err
}
if err := b.LoadBuilderConf(conf); err != nil {
+21 -24
View File
@@ -68,21 +68,24 @@ type mixerConf struct {
}
// LoadDefaults sets sane values for the config properties
func (config *MixConfig) LoadDefaults() error {
if !UseNewConfig {
return nil
}
func (config *MixConfig) LoadDefaults(localrpms bool) error {
pwd, err := os.Getwd()
if err != nil {
return err
}
config.LoadDefaultsForPath(localrpms, pwd)
return nil
}
// LoadDefaultsForPath sets sane values for config properties using `path` as base directory
func (config *MixConfig) LoadDefaultsForPath(localrpms bool, path string) {
// [Builder]
config.Builder.Cert = filepath.Join(pwd, "Swupd_Root.pem")
config.Builder.ServerStateDir = filepath.Join(pwd, "update")
config.Builder.VersionPath = pwd
config.Builder.DNFConf = filepath.Join(pwd, ".yum-mix.conf")
config.Builder.Cert = filepath.Join(path, "Swupd_Root.pem")
config.Builder.ServerStateDir = filepath.Join(path, "update")
config.Builder.VersionPath = path
config.Builder.DNFConf = filepath.Join(path, ".yum-mix.conf")
// [Swupd]
config.Swupd.Bundle = "os-core-update"
@@ -96,11 +99,15 @@ func (config *MixConfig) LoadDefaults() error {
config.Server.DebugInfoSrc = "/usr/src/debug"
// [Mixer]
config.Mixer.LocalBundleDir = filepath.Join(pwd, "local-bundles")
config.Mixer.LocalRPMDir = ""
config.Mixer.LocalRepoDir = ""
config.Mixer.LocalBundleDir = filepath.Join(path, "local-bundles")
return nil
if localrpms {
config.Mixer.LocalRPMDir = filepath.Join(path, "local-rpms")
config.Mixer.LocalRepoDir = filepath.Join(path, "local-yum")
} else {
config.Mixer.LocalRPMDir = ""
config.Mixer.LocalRepoDir = ""
}
}
// CreateDefaultConfig creates a default builder.conf using the active
@@ -110,20 +117,10 @@ func (config *MixConfig) CreateDefaultConfig(localrpms bool) error {
return config.createLegacyConfig(localrpms)
}
if err := config.LoadDefaults(); err != nil {
if err := config.LoadDefaults(localrpms); err != nil {
return err
}
if localrpms {
pwd, err := os.Getwd()
if err != nil {
return err
}
config.Mixer.LocalRPMDir = filepath.Join(pwd, "local-rpms")
config.Mixer.LocalRepoDir = filepath.Join(pwd, "local-yum")
}
filename, err := GetConfigPath("")
if err != nil {
return err