-
Notifications
You must be signed in to change notification settings - Fork 4
/
auditread.go
81 lines (75 loc) · 1.98 KB
/
auditread.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package action
import (
"path"
"slices"
"github.com/pkg/errors"
"github.com/samber/lo"
"projectforge.dev/projectforge/app/file"
"projectforge.dev/projectforge/app/lib/filesystem"
"projectforge.dev/projectforge/app/util"
)
func getGeneratedFiles(tgt filesystem.FileLoader, ignore []string, logger util.Logger) ([]string, error) {
filenames, err := tgt.ListFilesRecursive("", ignore, logger)
if err != nil {
return nil, err
}
var ret []string
for _, fn := range filenames {
b, e := tgt.PeekFile(fn, 1024)
if e != nil {
return nil, e
}
if file.ContainsHeader(string(b)) {
ret = append(ret, fn)
}
}
return ret, nil
}
func getModuleFiles(pm *PrjAndMods) ([]string, error) {
ret, err := pm.MSvc.GetFilenames(pm.Mods, pm.Logger)
if err != nil {
return nil, err
}
if pm.Mods.Get("export") != nil {
args, err := pm.Prj.ModuleArgExport(pm.PSvc, pm.Logger)
if err != nil {
return nil, err
}
args.Modules = pm.Mods.Keys()
lb := util.StringDefaultLinebreak
pfs, err := pm.PSvc.GetFilesystem(pm.Prj)
if err != nil {
return nil, err
}
modContent, _ := pfs.ReadFile("go.mod")
if modContent != nil {
lb = util.StringDetectLinebreak(string(modContent))
}
files, e := pm.ESvc.Files(pm.Prj, args, true, lb)
if e != nil {
return nil, err
}
lo.ForEach(files, func(f *file.File, _ int) {
ret = append(ret, f.FullPath())
})
}
return ret, nil
}
func getEmptyFolders(tgt filesystem.FileLoader, ignore []string, logger util.Logger, pth ...string) ([]string, error) {
var ret []string
pStr := path.Join(pth...)
fc := len(tgt.ListFiles(pStr, nil, logger))
ds := tgt.ListDirectories(pStr, ignore, logger)
if fc == 0 && len(ds) == 0 {
ret = append(ret, pStr)
}
for _, d := range ds {
p := append(slices.Clone(pth), d)
childRes, err := getEmptyFolders(tgt, ignore, logger, p...)
if err != nil {
return nil, errors.Wrapf(err, "unable to get empty folders for [%s/%s]", path.Join(p...), d)
}
ret = append(ret, childRes...)
}
return ret, nil
}