Skip to content

Commit fa96ddb

Browse files
zeripath6543
andauthored
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 <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent a3e8450 commit fa96ddb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

contrib/environment-to-ini/environment-to-ini.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func runEnvironmentToIni(c *cli.Context) error {
110110
}
111111
cfg.NameMapper = ini.SnackCase
112112

113+
changed := false
114+
113115
prefix := c.String("prefix") + "__"
114116

115117
for _, kv := range os.Environ() {
@@ -143,15 +145,21 @@ func runEnvironmentToIni(c *cli.Context) error {
143145
continue
144146
}
145147
}
148+
oldValue := key.Value()
149+
if !changed && oldValue != value {
150+
changed = true
151+
}
146152
key.SetValue(value)
147153
}
148154
destination := c.String("out")
149155
if len(destination) == 0 {
150156
destination = setting.CustomConf
151157
}
152-
err = cfg.SaveTo(destination)
153-
if err != nil {
154-
return err
158+
if destination != setting.CustomConf || changed {
159+
err = cfg.SaveTo(destination)
160+
if err != nil {
161+
return err
162+
}
155163
}
156164
if c.Bool("clear") {
157165
for _, kv := range os.Environ() {

0 commit comments

Comments
 (0)