瀏覽代碼

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 <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
tags/v1.15.0-rc1
zeripath 3 年之前
父節點
當前提交
bbbe625343
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 11 行新增3 行删除
  1. 11
    3
      contrib/environment-to-ini/environment-to-ini.go

+ 11
- 3
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() {

Loading…
取消
儲存