mirror of
https://github.com/clearlinux/mixer-tools.git
synced 2026-09-06 05:31:50 +00:00
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:
+1
-1
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user