Compare commits
No commits in common. "master" and "v0.7.1" have entirely different histories.
2 changed files with 6 additions and 18 deletions
22
tree.go
22
tree.go
|
@ -3,7 +3,6 @@ package zord_tree
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"cmp"
|
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -14,10 +13,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 {
|
||||||
|
@ -25,10 +24,10 @@ type Config struct {
|
||||||
AttachmentDirName string
|
AttachmentDirName string
|
||||||
CustomMeta map[string]func() string
|
CustomMeta map[string]func() string
|
||||||
Excludes []string
|
Excludes []string
|
||||||
Apps map[string]AppCallback
|
Apps map[string]appCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppCallback func(dir string, content string, info os.FileInfo) (string, error)
|
type appCallback func(dir string, content string, info os.FileInfo) (string, error)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Id string
|
Id string
|
||||||
|
@ -151,7 +150,7 @@ func NewConfig(
|
||||||
attachmentDirName string,
|
attachmentDirName string,
|
||||||
customMeta map[string]func() string,
|
customMeta map[string]func() string,
|
||||||
excludes []string,
|
excludes []string,
|
||||||
apps map[string]AppCallback,
|
apps map[string]appCallback,
|
||||||
) Config {
|
) Config {
|
||||||
return Config{
|
return Config{
|
||||||
ReadableFormats: readableFormats,
|
ReadableFormats: readableFormats,
|
||||||
|
@ -263,7 +262,7 @@ func moveAttachments(dir string, config Config) (map[string]string, error) {
|
||||||
return attachmentRegistry, err
|
return attachmentRegistry, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyApp(app AppCallback, dir string, config Config) error {
|
func applyApp(app appCallback, dir string, config Config) error {
|
||||||
err := filepath.Walk(dir, func(fullPath string, info os.FileInfo, e error) error {
|
err := filepath.Walk(dir, func(fullPath string, info os.FileInfo, e error) error {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
|
@ -296,7 +295,7 @@ func applyApp(app AppCallback, dir string, config Config) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err = app(path.Dir(fullPath), content, info)
|
content, err = app(dir, content, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -569,16 +568,7 @@ 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,7 +22,6 @@ 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)
|
||||||
|
@ -39,7 +38,6 @@ 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