From 3ba652743c8f73dffb645ae574c2549f1b000466 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 22 Nov 2024 09:00:05 -0600 Subject: rename. add notes Signed-off-by: Jeff Carr --- readonly.go | 101 ------------------------------------------------------- settings.go | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 101 deletions(-) delete mode 100644 readonly.go create mode 100644 settings.go diff --git a/readonly.go b/readonly.go deleted file mode 100644 index 9d0c1e9..0000000 --- a/readonly.go +++ /dev/null @@ -1,101 +0,0 @@ -package forgepb - -import ( - "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() -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 - } - } - // 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? -func (all *Repos) IsPrivate(gopath 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 == gopath { - // if private is set here, then ok, otherwise - // still check if a Directory match exists - if r.Private { - return true - } - } - // 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 IsPrivate()", gopath) - return false - } - - // otherwise, assume not private - return match.Private -} diff --git a/settings.go b/settings.go new file mode 100644 index 0000000..afe5e8a --- /dev/null +++ b/settings.go @@ -0,0 +1,110 @@ +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 ( + "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() +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 + } + } + // 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? +func (all *Repos) IsPrivate(gopath 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 == gopath { + // if private is set here, then ok, otherwise + // still check if a Directory match exists + if r.Private { + return true + } + } + // 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 IsPrivate()", gopath) + return false + } + + // otherwise, assume not private + return match.Private +} -- cgit v1.2.3