Trim BOM from config file for windows support

Default windows text editor (Notepad) adds a BOM to the beginning of the
file. This needs to be trimmed otherwise we will get an "invalid toml"
error.

see https://github.com/influxdata/telegraf/issues/1378
and http://utf8everywhere.org/#faq.boms
pull/6900/head
Cameron Sparr 2016-06-23 09:19:39 +01:00
parent b8e52ce39a
commit 98360c50d5
2 changed files with 10 additions and 0 deletions

View File

@ -29,6 +29,7 @@ With this release the systemd configuration files for InfluxDB will use the syst
- [#6820](https://github.com/influxdata/influxdb/issues/6820): Add NodeID to execution options - [#6820](https://github.com/influxdata/influxdb/issues/6820): Add NodeID to execution options
- [#4532](https://github.com/influxdata/influxdb/issues/4532): Support regex selection in SHOW TAG VALUES for the key. - [#4532](https://github.com/influxdata/influxdb/issues/4532): Support regex selection in SHOW TAG VALUES for the key.
- [#6889](https://github.com/influxdata/influxdb/pull/6889): Update help and remove unused config options from the configuration file. - [#6889](https://github.com/influxdata/influxdb/pull/6889): Update help and remove unused config options from the configuration file.
- [#6900](https://github.com/influxdata/influxdb/pull/6900): Trim BOM from Windows Notepad-saved config files.
### Bugfixes ### Bugfixes

View File

@ -1,6 +1,7 @@
package run package run
import ( import (
"bytes"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -110,12 +111,20 @@ func NewDemoConfig() (*Config, error) {
return c, nil return c, nil
} }
// trimBOM trims the Byte-Order-Marks from the beginning of the file.
// this is for Windows compatability only.
// see https://github.com/influxdata/telegraf/issues/1378
func trimBOM(f []byte) []byte {
return bytes.TrimPrefix(f, []byte("\xef\xbb\xbf"))
}
// FromTomlFile loads the config from a TOML file. // FromTomlFile loads the config from a TOML file.
func (c *Config) FromTomlFile(fpath string) error { func (c *Config) FromTomlFile(fpath string) error {
bs, err := ioutil.ReadFile(fpath) bs, err := ioutil.ReadFile(fpath)
if err != nil { if err != nil {
return err return err
} }
bs = trimBOM(bs)
return c.FromToml(string(bs)) return c.FromToml(string(bs))
} }