Skip to content

Commit

Permalink
Only write config in environment-to-ini if there are changes (#15861) (
Browse files Browse the repository at this point in the history
…#15868)

Backport #15861

* Only write config in environment-to-ini if there are changes

Only write the new config in environment-to-ini if there are changes or the
destination is not the same as the customconf.

Fix #15719
Fix #15857

Signed-off-by: Andrew Thornton <[email protected]>
Co-authored-by: 6543 <[email protected]>

Co-authored-by: 6543 <[email protected]>
  • Loading branch information
zeripath and 6543 authored May 15, 2021
1 parent a3e8450 commit fa96ddb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions contrib/environment-to-ini/environment-to-ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ func runEnvironmentToIni(c *cli.Context) error {
}
cfg.NameMapper = ini.SnackCase

changed := false

prefix := c.String("prefix") + "__"

for _, kv := range os.Environ() {
Expand Down Expand Up @@ -143,15 +145,21 @@ func runEnvironmentToIni(c *cli.Context) error {
continue
}
}
oldValue := key.Value()
if !changed && oldValue != value {
changed = true
}
key.SetValue(value)
}
destination := c.String("out")
if len(destination) == 0 {
destination = setting.CustomConf
}
err = cfg.SaveTo(destination)
if err != nil {
return err
if destination != setting.CustomConf || changed {
err = cfg.SaveTo(destination)
if err != nil {
return err
}
}
if c.Bool("clear") {
for _, kv := range os.Environ() {
Expand Down

0 comments on commit fa96ddb

Please sign in to comment.