-
Notifications
You must be signed in to change notification settings - Fork 150
/
update.go
73 lines (66 loc) · 1.86 KB
/
update.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
package main
import (
"fmt"
"log"
"os"
"path"
"path/filepath"
"strings"
)
func updateType(name string, dict map[string]typeInfo, filepath string, configType string) (typeInfo, error) {
var tInfo typeInfo
tInfo = dict[name]
_, err := tInfo.generate(filepath, configType)
return tInfo, err
}
func updateIndex(configType string, idx map[string]map[string]typeInfo, tmpIdx map[string]map[string]typeInfo) {
var files []string
//tInfo := make(map[string]typeInfo)
folder := path.Join("./", configType)
idx[configType] = make(map[string]typeInfo)
err := filepath.Walk(folder, func(path string, info os.FileInfo, err error) error {
if strings.HasSuffix(path, ".yaml") || strings.HasSuffix(path, ".yml") {
files = append(files, path)
}
return nil
})
if err != nil {
panic(err)
}
log.Printf("Updating stuff for %s", configType)
for _, filepath := range files {
var foundFile bool
foundFile = false
// only deal with filepath that starts with parsers/scenarios/postoverflows
if strings.HasPrefix(filepath, folder) {
// we are going to check if the file is already in the index to update it
if val, ok := tmpIdx[configType]; ok {
var tInfo typeInfo
var hubName string
for name, info := range val {
if filepath == info.Path {
tInfo, err = updateType(name, val, filepath, configType)
if err != nil {
fmt.Printf("skipping '%s' because: %s\n", name, err)
}
hubName = name
foundFile = true
break
}
}
if foundFile {
idx[configType][hubName] = tInfo
} else {
// the file was not found in the .index, creating a new entry
var tInfo typeInfo
hubName, err := tInfo.generate(filepath, configType)
if err != nil {
fmt.Printf("skipping '%s' for update because : %s\n", filepath, err.Error())
} else {
idx[configType][hubName] = tInfo
}
}
}
}
}
}