From fa96ddb327946eafcf39ab38cbe61bceb91aa649 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 15 May 2021 13:07:16 +0100 Subject: [PATCH] Only write config in environment-to-ini if there are changes (#15861) (#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 Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@obermui.de> --- contrib/environment-to-ini/environment-to-ini.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/contrib/environment-to-ini/environment-to-ini.go b/contrib/environment-to-ini/environment-to-ini.go index 74379e26af..aade251902 100644 --- a/contrib/environment-to-ini/environment-to-ini.go +++ b/contrib/environment-to-ini/environment-to-ini.go @@ -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() { @@ -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() {