diff options
| author | Jeff Carr <[email protected]> | 2024-12-04 15:36:49 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-04 15:36:49 -0600 |
| commit | f98179971e574de202c582576e59a8e3da68530f (patch) | |
| tree | d7ae78b10ea961722015a658e82cb13dbe92ad2d /repoSettings.go | |
| parent | 4d221c522035e05947b136385e23b78eccc9c578 (diff) | |
this .proto might allow generic marshal recovery
Diffstat (limited to 'repoSettings.go')
| -rw-r--r-- | repoSettings.go | 209 |
1 files changed, 0 insertions, 209 deletions
diff --git a/repoSettings.go b/repoSettings.go deleted file mode 100644 index 128d1a1..0000000 --- a/repoSettings.go +++ /dev/null @@ -1,209 +0,0 @@ -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" - - "go.wit.com/lib/protobuf/gitpb" -) - -/* -func (f *Forge) SortByGoPath() *ForgeConfigIterator { - return f.Config.SortByPath() -} -*/ - -/* -func (all *ForgeConfigs) UpdateGoPath(name string, gopath string) bool { - oldr := all.DeleteByGoPath(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 (f *Forge) IsReadOnly(repo *gitpb.Repo) bool { - // var match *ForgeConfig - - return f.Config.IsReadOnly(repo.GoPath) -} - -// returns true if gopath is readonly() -// will attempt to match IsWritable("foo") against anything ending in "foo" -func (f *ForgeConfigs) IsReadOnly(gopath string) bool { - var match *ForgeConfig - - - loop := f.SortByGoPath() // get the list of repos - for loop.Scan() { - r := loop.Next() - 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 -} - -// 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 (f *Forge) DebName(gopath string) string { - // get "zookeeper" from "go.wit.com/apps/zookeeper" - normalBase := filepath.Base(gopath) - - loop := f.Config.SortByGoPath() - for loop.Scan() { - r := loop.Next() - 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 -} - -// 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 (f *Forge) IsPrivate(thing string) bool { - var match *ForgeConfig - - // sort by path means the simple 'match' logic - // here works in the sense the last directory match - // is the one that is used - loop := f.Config.SortByGoPath() // get the list of repos - for loop.Scan() { - r := loop.Next() - 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 -} - -// IsFavorite() -- fun option for the config -// file that lets you set things as favorites -// so you can just go-clone a bunch of common things -// on a new box or after you reset/delete your ~/go/src dir -func (f *Forge) IsFavorite(thing string) bool { - var match *ForgeConfig - - loop := f.Config.SortByGoPath() // get the list of repos - for loop.Scan() { - r := loop.Next() - if r.GoPath == thing { - if r.Favorite { - return true - } - } - base := filepath.Base(r.GoPath) - if base == thing { - if r.Favorite { - return true - } - } - if r.Directory { - if strings.HasPrefix(thing, r.GoPath) { - match = r - } - } - } - if match == nil { - return false - } - - return match.Favorite -} |
