fixing build version checking logic

This commit is contained in:
Jeff Carr 2024-11-22 19:11:22 -06:00
parent 5f65e4f4be
commit 7025f6b7e5
1 changed files with 33 additions and 9 deletions

View File

@ -27,6 +27,7 @@ func (all *Repos) UpdateGoPath(name string, gopath string) bool {
} }
// returns true if gopath is readonly() // returns true if gopath is readonly()
// will attempt to match IsWritable("foo") against anything ending in "foo"
func (all *Repos) IsReadOnly(gopath string) bool { func (all *Repos) IsReadOnly(gopath string) bool {
var match *Repo var match *Repo
@ -46,6 +47,13 @@ func (all *Repos) IsReadOnly(gopath string) bool {
return false 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 // search for potential dir matches
if r.Directory { if r.Directory {
// test the dir // test the dir
@ -77,7 +85,13 @@ func (all *Repos) IsReadOnly(gopath string) bool {
} }
// is this a non-publishable repo? // is this a non-publishable repo?
func (all *Repos) IsPrivate(gopath string) bool { // 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 var match *Repo
// sort by path means the simple 'match' logic // sort by path means the simple 'match' logic
@ -86,23 +100,30 @@ func (all *Repos) IsPrivate(gopath string) bool {
loop := all.SortByPath() // get the list of repos loop := all.SortByPath() // get the list of repos
for loop.Scan() { for loop.Scan() {
r := loop.Repo() r := loop.Repo()
if r.GoPath == gopath { if r.GoPath == thing {
// if private is set here, then ok, otherwise // if private is set here, then ok, otherwise
// still check if a Directory match exists // still check if a Directory match exists
if r.Private { if r.Private {
return true 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 // search for potential dir matches
if r.Directory { if r.Directory {
// test the dir // test the dir
if strings.HasPrefix(gopath, r.GoPath) { if strings.HasPrefix(thing, r.GoPath) {
match = r match = r
} }
} }
} }
if match == nil { if match == nil {
// log.Info("did not match in IsPrivate()", gopath) // log.Info("did not match in IsPrivate()", thing)
return false return false
} }
@ -110,18 +131,21 @@ func (all *Repos) IsPrivate(gopath string) bool {
return match.Private return match.Private
} }
// returns the deb package // 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 { func (all *Repos) DebName(gopath string) string {
// get "zookeeper" from "go.wit.com/apps/zookeeper"
normalBase := filepath.Base(gopath) normalBase := filepath.Base(gopath)
loop := all.SortByPath() loop := all.SortByPath()
for loop.Scan() { for loop.Scan() {
r := loop.Repo() r := loop.Repo()
if r.GoPath == gopath { if r.GoPath == gopath {
// if private is set here, then ok, otherwise // returns "zookeeper-go" for "go.wit.com/apps/zookeeper"
// still check if a Directory match exists if r.DebName != "" {
if r.DebName == "" { // log.Info("FOUND DebName", r.DebName)
return r.DebName return r.DebName
} else { } else {
return normalBase return normalBase