Sort arguments in Meta.process

Meta.process was relying on the system readdir to order the arguments,
but readdir doesn't guarantee any ordering. Read the directory contents
as a whole and sort them in place before adding the tfvars files.
This commit is contained in:
James Bardin 2017-07-06 11:34:47 -04:00
parent 0fdcf2c01e
commit f7f1e8e406
1 changed files with 14 additions and 25 deletions

View File

@ -11,6 +11,7 @@ import (
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -398,27 +399,16 @@ func (m *Meta) process(args []string, vars bool) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
f, err := os.Open(wd)
fis, err := ioutil.ReadDir(wd)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer f.Close()
fi, err := f.Stat() // make sure we add the files in order
if err != nil { sort.Slice(fis, func(i, j int) bool {
return nil, err return fis[i].Name() < fis[j].Name()
} })
if !fi.IsDir() {
return nil, err
}
err = nil
for err != io.EOF {
var fis []os.FileInfo
fis, err = f.Readdir(128)
if err != nil && err != io.EOF {
return nil, err
}
for _, fi := range fis { for _, fi := range fis {
name := fi.Name() name := fi.Name()
@ -430,7 +420,6 @@ func (m *Meta) process(args []string, vars bool) ([]string, error) {
m.autoKey = "var-file-default" m.autoKey = "var-file-default"
preArgs = append(preArgs, "-"+m.autoKey, name) preArgs = append(preArgs, "-"+m.autoKey, name)
} }
}
args = append(preArgs, args...) args = append(preArgs, args...)
} }