blob: e5bc65ca0e3a384fc03f5494347bca82daa87af6 (
plain)
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
|
package forgepb
/*
check settings for a particular gopath
this provides checks for:
IsReadOnly() // user can't push commits
IsPrivate() // repo can't be published to the pkg.go.dev system
DebName() // for 'zookeeper' returns 'zookeeper-go'
*/
import (
"path/filepath"
"strings"
)
func (all *Repos) UpdateGoPath(name string, gopath string) bool {
oldr := all.DeleteByPath(name)
if oldr == nil {
// nothing to update
return false
}
// update gopath and append it back to the list
oldr.GoPath = gopath
return all.Append(oldr)
}
// returns true if gopath is readonly()
// will attempt to match IsWritable("foo") against anything ending in "foo"
func (all *Repos) IsReadOnly(gopath string) bool {
var match *Repo
loop := all.SortByPath() // get the list of repos
for loop.Scan() {
r := loop.Repo()
if r.GoPath == gopath {
// exact gopath match
if r.Writable {
return false
}
if r.ReadOnly {
return true
}
// private is assumed to be r/w unless above is specifically set
if r.Private {
return false
}
}
// if gopath == "foo" will return false if "go.wit.com/apps/foo" is Writable
base := filepath.Base(r.GoPath)
if base == gopath {
if r.Writable {
return false
}
}
// search for potential dir matches
if r.Directory {
// test the dir
if strings.HasPrefix(gopath, r.GoPath) {
match = r
}
}
}
if match == nil {
// log.Info("did not match in IsReadOnly()", gopath)
return true
}
// take the settings from the directory match
if match.Writable {
return false
}
if match.ReadOnly {
return true
}
// private is assumed to be r/w unless above is specifically set
if match.Private {
return false
}
// always assume readonly
return true
}
// is this a non-publishable repo?
// matches package names from apt
//
// IsPrivate("foo") will match anything in the config file ending in "foo"
//
// IsPrivate("go.foo.com/jcarr/foo") returns true if private
// IsPrivate("foo") also returns true if "go.bar.com/jcarr/foo" is private
func (all *Repos) IsPrivate(thing string) bool {
var match *Repo
// sort by path means the simple 'match' logic
// here works in the sense the last directory match
// is the one that is used
loop := all.SortByPath() // get the list of repos
for loop.Scan() {
r := loop.Repo()
if r.GoPath == thing {
// if private is set here, then ok, otherwise
// still check if a Directory match exists
if r.Private {
return true
}
}
base := filepath.Base(r.GoPath)
if base == thing {
if r.Private {
return true
}
}
// check to see if IsPrivate("foo")
// search for potential dir matches
if r.Directory {
// test the dir
if strings.HasPrefix(thing, r.GoPath) {
match = r
}
}
}
if match == nil {
// log.Info("did not match in IsPrivate()", thing)
return false
}
// otherwise, assume not private
return match.Private
}
// returns the deb package name
// this let's you check a git tag version against a package .deb version
// allows gopath's to not need to match the .deb name
// this is important in lots of cases! It is normal and happens often enough.
func (all *Repos) DebName(gopath string) string {
// get "zookeeper" from "go.wit.com/apps/zookeeper"
normalBase := filepath.Base(gopath)
loop := all.SortByPath()
for loop.Scan() {
r := loop.Repo()
if r.GoPath == gopath {
// returns "zookeeper-go" for "go.wit.com/apps/zookeeper"
if r.DebName != "" {
// log.Info("FOUND DebName", r.DebName)
return r.DebName
} else {
return normalBase
}
}
}
return normalBase
}
|