-
-
Notifications
You must be signed in to change notification settings - Fork 362
/
dep.go
174 lines (135 loc) · 3.1 KB
/
dep.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package main
import (
"fmt"
"strings"
alpm "github.com/Jguer/go-alpm"
rpc "github.com/mikkeloscar/aur"
)
type providers struct {
lookfor string
Pkgs []*rpc.Pkg
}
func makeProviders(name string) providers {
return providers{
name,
make([]*rpc.Pkg, 0),
}
}
func (q providers) Len() int {
return len(q.Pkgs)
}
func (q providers) Less(i, j int) bool {
if q.lookfor == q.Pkgs[i].Name {
return true
}
if q.lookfor == q.Pkgs[j].Name {
return false
}
return lessRunes([]rune(q.Pkgs[i].Name), []rune(q.Pkgs[j].Name))
}
func (q providers) Swap(i, j int) {
q.Pkgs[i], q.Pkgs[j] = q.Pkgs[j], q.Pkgs[i]
}
func splitDep(dep string) (string, string, string) {
mod := ""
split := strings.FieldsFunc(dep, func(c rune) bool {
match := c == '>' || c == '<' || c == '='
if match {
mod += string(c)
}
return match
})
if len(split) == 0 {
return "", "", ""
}
if len(split) == 1 {
return split[0], "", ""
}
return split[0], mod, split[1]
}
func pkgSatisfies(name, version, dep string) bool {
depName, depMod, depVersion := splitDep(dep)
if depName != name {
return false
}
return verSatisfies(version, depMod, depVersion)
}
func provideSatisfies(provide, dep string) bool {
depName, depMod, depVersion := splitDep(dep)
provideName, provideMod, provideVersion := splitDep(provide)
if provideName != depName {
return false
}
// Unversioned provieds can not satisfy a versioned dep
if provideMod == "" && depMod != "" {
return false
}
return verSatisfies(provideVersion, depMod, depVersion)
}
func verSatisfies(ver1, mod, ver2 string) bool {
switch mod {
case "=":
return alpm.VerCmp(ver1, ver2) == 0
case "<":
return alpm.VerCmp(ver1, ver2) < 0
case "<=":
return alpm.VerCmp(ver1, ver2) <= 0
case ">":
return alpm.VerCmp(ver1, ver2) > 0
case ">=":
return alpm.VerCmp(ver1, ver2) >= 0
}
return true
}
func satisfiesAur(dep string, pkg *rpc.Pkg) bool {
if pkgSatisfies(pkg.Name, pkg.Version, dep) {
return true
}
for _, provide := range pkg.Provides {
if provideSatisfies(provide, dep) {
return true
}
}
return false
}
func satisfiesRepo(dep string, pkg *alpm.Package) bool {
if pkgSatisfies(pkg.Name(), pkg.Version(), dep) {
return true
}
if pkg.Provides().ForEach(func(provide alpm.Depend) error {
if provideSatisfies(provide.String(), dep) {
return fmt.Errorf("")
}
return nil
}) != nil {
return true
}
return false
}
//split apart db/package to db and package
func splitDBFromName(pkg string) (string, string) {
split := strings.SplitN(pkg, "/", 2)
if len(split) == 2 {
return split[0], split[1]
}
return "", split[0]
}
func getBases(pkgs []*rpc.Pkg) []Base {
basesMap := make(map[string]Base)
for _, pkg := range pkgs {
basesMap[pkg.PackageBase] = append(basesMap[pkg.PackageBase], pkg)
}
bases := make([]Base, 0, len(basesMap))
for _, base := range basesMap {
bases = append(bases, base)
}
return bases
}
func isDevelName(name string) bool {
for _, suffix := range []string{"git", "svn", "hg", "bzr", "nightly"} {
if strings.HasSuffix(name, "-"+suffix) {
return true
}
}
return strings.Contains(name, "-always-")
}