-
Notifications
You must be signed in to change notification settings - Fork 0
/
fstree.go
33 lines (29 loc) · 898 Bytes
/
fstree.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package filesystem
import (
"path"
"admini.dev/admini/app/util"
)
func (f *FileSystem) listNodes(pth string, ign []string, logger util.Logger, tags ...string) (Nodes, error) {
files := f.ListFiles(pth, ign, logger)
nodes := make(Nodes, 0, len(files))
for _, fi := range files {
x := path.Join(pth, fi.Name)
if fi.IsDir {
kids, err := f.listNodes(x, ign, logger)
if err != nil {
return nil, err
}
nodes = append(nodes, &Node{Name: fi.Name, Dir: true, Children: kids, Tags: tags})
} else {
nodes = append(nodes, &Node{Name: fi.Name, Tags: tags, Size: f.Size(x)})
}
}
return nodes.Sort(), nil
}
func (f *FileSystem) ListTree(cfg util.ValueMap, pth string, ign []string, logger util.Logger, tags ...string) (*Tree, error) {
nodes, err := f.listNodes(pth, ign, logger, tags...)
if err != nil {
return nil, err
}
return &Tree{Config: cfg, Nodes: nodes}, nil
}