From bbbe625343c8dbe216c4ba6f46b336ca0f7f2e47 Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 14 May 2021 00:01:05 +0100 Subject: [PATCH] Only write config in environment-to-ini if there are changes (#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> --- 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() {