diff --git a/command/agent/config.go b/command/agent/config.go index fb707218d7..345b638b10 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -9,6 +9,7 @@ import ( "io" "os" "path/filepath" + "sort" "strings" ) @@ -75,6 +76,8 @@ type Config struct { ConsulConfig *consul.Config } +type dirEnts []os.FileInfo + // DefaultConfig is used to return a sane default configuration func DefaultConfig() *Config { return &Config{ @@ -205,6 +208,9 @@ func ReadConfigPaths(paths []string) (*Config, error) { return nil, fmt.Errorf("Error reading '%s': %s", path, err) } + // Sort the contents, ensures lexical order + sort.Sort(dirEnts(contents)) + for _, fi := range contents { // Don't recursively read contents if fi.IsDir() { @@ -235,3 +241,16 @@ func ReadConfigPaths(paths []string) (*Config, error) { return result, nil } + +// Implement the sort interface for dirEnts +func (d dirEnts) Len() int { + return len(d) +} + +func (d dirEnts) Less(i, j int) bool { + return d[i].Name() < d[j].Name() +} + +func (d dirEnts) Swap(i, j int) { + d[i], d[j] = d[j], d[i] +}