Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
|
cba38255a5 | ||
|
13ab5b1902 | ||
|
873110f5ce |
2 changed files with 14 additions and 2 deletions
14
tree.go
14
tree.go
|
@ -3,6 +3,7 @@ package zord_tree
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"cmp"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -13,10 +14,10 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
abcex "g.arns.lt/zordsdavini/abcex/v4"
|
abcex "g.arns.lt/zordsdavini/abcex/v4"
|
||||||
"golang.org/x/exp/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -295,7 +296,7 @@ func applyApp(app AppCallback, dir string, config Config) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err = app(dir, content, info)
|
content, err = app(path.Dir(fullPath), content, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -568,7 +569,16 @@ FILE_LOOP:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tree, err
|
return tree, err
|
||||||
}
|
}
|
||||||
|
if nextFile.Id == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
tree.Files = append(tree.Files, nextFile)
|
tree.Files = append(tree.Files, nextFile)
|
||||||
|
slices.SortFunc(tree.Files, func(a, b File) int {
|
||||||
|
if len(a.Id) == len(b.Id) {
|
||||||
|
return strings.Compare(a.Id, b.Id)
|
||||||
|
}
|
||||||
|
return cmp.Compare(len(a.Id), len(b.Id))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return tree, nil
|
return tree, nil
|
||||||
|
|
|
@ -22,6 +22,7 @@ func prepare(t *testing.T) Config {
|
||||||
"__a",
|
"__a",
|
||||||
make(map[string]func() string),
|
make(map[string]func() string),
|
||||||
[]string{"exclude_[0-9]+.bin"},
|
[]string{"exclude_[0-9]+.bin"},
|
||||||
|
map[string]AppCallback{},
|
||||||
)
|
)
|
||||||
|
|
||||||
err = PopulateTree("./testdata/sunny1", []string{}, config)
|
err = PopulateTree("./testdata/sunny1", []string{}, config)
|
||||||
|
@ -38,6 +39,7 @@ func TestFromNotExistingDirectory(t *testing.T) {
|
||||||
"__a",
|
"__a",
|
||||||
make(map[string]func() string),
|
make(map[string]func() string),
|
||||||
[]string{},
|
[]string{},
|
||||||
|
map[string]AppCallback{},
|
||||||
)
|
)
|
||||||
|
|
||||||
_, err := BuildTree("./testing/i_dont_exist", []string{}, config)
|
_, err := BuildTree("./testing/i_dont_exist", []string{}, config)
|
||||||
|
|
Loading…
Add table
Reference in a new issue