diff --git a/asset.go b/asset.go index 51771a8..95b6b94 100644 --- a/asset.go +++ b/asset.go @@ -10,10 +10,3 @@ type Asset struct { Name string // Key used in TOC -- name by which asset is referenced. Func string // Function name for the procedure returning the asset contents. } - -// Implement sort.Interface for []Asset based on Path field -type ByPath []Asset - -func (v ByPath) Len() int { return len(v) } -func (v ByPath) Swap(i, j int) { v[i], v[j] = v[j], v[i] } -func (v ByPath) Less(i, j int) bool { return v[i].Path < v[j].Path } diff --git a/convert.go b/convert.go index 335ca62..410d1de 100644 --- a/convert.go +++ b/convert.go @@ -35,9 +35,6 @@ func Translate(c *Config) error { } } - // Sort to make output stable between invocations - sort.Sort(ByPath(toc)) - // Create output file. fd, err := os.Create(c.Output) if err != nil { @@ -83,6 +80,13 @@ func Translate(c *Config) error { return writeTOCTree(bfd, toc) } +// Implement sort.Interface for []os.FileInfo based on Name() +type ByName []os.FileInfo + +func (v ByName) Len() int { return len(v) } +func (v ByName) Swap(i, j int) { v[i], v[j] = v[j], v[i] } +func (v ByName) Less(i, j int) bool { return v[i].Name() < v[j].Name() } + // findFiles recursively finds all the file paths in the given directory tree. // They are added to the given map as keys. Values will be safe function names // for each file, which will be used when generating the output code. @@ -115,6 +119,9 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regex if err != nil { return err } + + // Sort to make output stable between invocations + sort.Sort(ByName(list)) } knownFuncs := make(map[string]int)