Compare commits

..

5 commits

Author SHA1 Message Date
Arnas Udovic
cba38255a5 skip Files without Id; sort Files by Id
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2025-04-06 09:30:35 +03:00
Arnas Udovic
13ab5b1902 fix test
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2025-01-12 01:03:47 +02:00
Arnas Udovic
873110f5ce fix apply AppCallback
Some checks reported errors
continuous-integration/drone/tag Build was killed
2025-01-12 00:30:28 +02:00
Arnas Udovic
97de2fd06c export AppCallback
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/tag Build was killed
continuous-integration/drone Build is failing
2025-01-12 00:18:49 +02:00
Arnas Udovic
1b06291e8d fix NewConfig
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/tag Build was killed
2025-01-12 00:15:45 +02:00
2 changed files with 19 additions and 5 deletions

22
tree.go
View file

@ -3,6 +3,7 @@ package zord_tree
import (
"bufio"
"bytes"
"cmp"
"crypto/md5"
"errors"
"fmt"
@ -13,10 +14,10 @@ import (
"path"
"path/filepath"
"regexp"
"slices"
"strings"
abcex "g.arns.lt/zordsdavini/abcex/v4"
"golang.org/x/exp/slices"
)
type Config struct {
@ -24,10 +25,10 @@ type Config struct {
AttachmentDirName string
CustomMeta map[string]func() 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 {
Id string
@ -150,12 +151,14 @@ func NewConfig(
attachmentDirName string,
customMeta map[string]func() string,
excludes []string,
apps map[string]AppCallback,
) Config {
return Config{
ReadableFormats: readableFormats,
AttachmentDirName: attachmentDirName,
CustomMeta: customMeta,
Excludes: excludes,
Apps: apps,
}
}
@ -260,7 +263,7 @@ func moveAttachments(dir string, config Config) (map[string]string, error) {
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 {
if e != nil {
return e
@ -293,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 {
return err
}
@ -566,7 +569,16 @@ FILE_LOOP:
if err != nil {
return tree, err
}
if nextFile.Id == "" {
continue
}
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

View file

@ -22,6 +22,7 @@ func prepare(t *testing.T) Config {
"__a",
make(map[string]func() string),
[]string{"exclude_[0-9]+.bin"},
map[string]AppCallback{},
)
err = PopulateTree("./testdata/sunny1", []string{}, config)
@ -38,6 +39,7 @@ func TestFromNotExistingDirectory(t *testing.T) {
"__a",
make(map[string]func() string),
[]string{},
map[string]AppCallback{},
)
_, err := BuildTree("./testing/i_dont_exist", []string{}, config)