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