summaryrefslogtreecommitdiff
path: root/update.go
diff options
context:
space:
mode:
Diffstat (limited to 'update.go')
-rw-r--r--update.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/update.go b/update.go
index 8dce1a0..8743ee1 100644
--- a/update.go
+++ b/update.go
@@ -1,5 +1,7 @@
package forgepb
+import "strings"
+
func (all *Repos) UpdateGoPath(name string, gopath string) bool {
oldr := all.DeleteByPath(name)
if oldr == nil {
@@ -11,3 +13,79 @@ func (all *Repos) UpdateGoPath(name string, gopath string) bool {
oldr.GoPath = gopath
return all.Append(oldr)
}
+
+// returns true if gopath is readonly()
+func (all *Repos) ReadOnly(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
+ }
+ }
+ }
+
+ // 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) Private(gopath string) bool {
+ var match *Repo
+
+ 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.Private {
+ return true
+ }
+
+ // otherwise, assume not private
+ return true
+}