-
Notifications
You must be signed in to change notification settings - Fork 0
/
packages_check.go
122 lines (86 loc) · 2.44 KB
/
packages_check.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package checker
import (
"strings"
"bufio"
"net/http"
)
var recmmended = []string{"Description"}
var deprecated = []string{"Version"}
func init() {
DefineCheck(func(url string, r Results) {
exists := r.BeginTest("Checking for .../packages.list")
res, err := MustHttp200(url + "/packages.list")
if err != nil {
exists.Fail("Failed to get package list: %s", err.Error())
return
}
defer res.Body.Close()
exists.Success()
valid := r.BeginTest("Checking Packages...")
pkgs := 0
reader := bufio.NewReader(res.Body)
line, _, err := reader.ReadLine()
for err == nil {
pkgs++
parts := strings.Split(string(line), "::")
var pkg Results
if len(parts) == 3 {
pkg = valid.BeginTest("Checking package %s", parts[0])
check_package(url+"/"+parts[0], pkg)
} else {
valid.Fail("Invalid package on line %d", pkgs)
return
}
line, _, err = reader.ReadLine()
}
valid.Done()
})
}
func check_package(url string, r Results) {
res, err := MustHttp200(url)
if err != nil {
r.Fail("Failed to get details.pkg: %s", err.Error())
return
}
defer res.Body.Close()
reader := bufio.NewReader(res.Body)
line, _, err := reader.ReadLine()
warned_blank := false
warned_invalid := false
directives := make(map[string][]string)
for err == nil {
str_line := string(line)
if str_line == "" && !warned_blank {
r.Warn("Previous verisons of ac-get didn't work with blank lines in the details.pkg")
warned_blank = true
}
parts := strings.SplitN(str_line, ": ", 2)
if len(parts) != 2 && !warned_invalid {
r.Warn("Previous versions of ac-get will fail to parse this.")
warned_invalid = true
} else {
if _, ok := directives[parts[0]]; !ok {
directives[parts[0]] = []string{}
}
directives[parts[0]] = append(directives[parts[0]], parts[1])
}
line, _, err = reader.ReadLine()
}
for _, rec := range recmmended {
if _, ok := directives[rec]; !ok {
r.Warn("Missing recommended directive: %s", rec)
}
}
for _, dep := range deprecated {
if _, ok := directives[dep]; ok {
r.Warn("Contains deprecated directive %s", dep)
}
}
if check_files(url+"/lib", directives["Library"], ".lua", r) &&
check_files(url+"/bin", directives["Executable"], ".lua", r) &&
check_files(url+"/cfg", directives["Config"], "", r) &&
check_files(url+"/startup", directives["Startup"], ".lua", r) &&
check_files(url+"/docs", directives["Documentation"], ".txt", r) {
r.Success()
}
}