From ce06800c41750f901c43cb35bcf9df8863dc3686 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 20 Nov 2024 21:22:05 -0600 Subject: [PATCH] boo. was wrong. had to redo a lot --- config.go | 1 + forgeConfig/main.go | 26 ++++++++++++++------------ repo.proto | 18 +++++++++--------- repos.go | 26 +++++++++++++------------- sampleConfig.go | 40 ++++++++++++++++++++-------------------- update.go | 2 +- 6 files changed, 58 insertions(+), 55 deletions(-) diff --git a/config.go b/config.go index 23e0435..fe70446 100644 --- a/config.go +++ b/config.go @@ -109,6 +109,7 @@ func (m *Repos) ConfigLoad() error { return nil } + m.SampleConfig() // first time user. make a template config file return nil } diff --git a/forgeConfig/main.go b/forgeConfig/main.go index 20df841..434f222 100644 --- a/forgeConfig/main.go +++ b/forgeConfig/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "os" "go.wit.com/lib/protobuf/forgepb" @@ -20,39 +19,41 @@ func main() { } if argv.List { log.Info(forgepb.RepoHeader()) - loop := repos.SortByName() // get the list of repos + loop := repos.SortByPath() // get the list of repos for loop.Scan() { r := loop.Repo() - log.Info("repo:", r.Name, r.GoPath) + log.Info("repo:", r.GoPath) } os.Exit(0) } if argv.Update { - if repos.UpdateGoPath(argv.Name, argv.GoPath) { - // save updated config file - repos.ConfigSave() - } + /* + if repos.UpdateGoPath(argv.Name, argv.GoPath) { + // save updated config file + repos.ConfigSave() + } + */ os.Exit(0) } if argv.Add { - log.Info("going to add a new repo", argv.Name, argv.GoPath) + log.Info("going to add a new repo", argv.GoPath) new1 := new(forgepb.Repo) - new1.Name = argv.Name new1.GoPath = argv.GoPath if repos.Append(new1) { - log.Info("added", new1.Name, "ok") + log.Info("added", new1.GoPath, "ok") } else { - log.Info("added", new1.Name, "failed") + log.Info("added", new1.GoPath, "failed") os.Exit(-1) } repos.ConfigSave() os.Exit(0) } - testMemoryCorruption(repos) + // testMemoryCorruption(repos) repos.ConfigSave() } +/* // this fucks shit up func testMemoryCorruption(all *forgepb.Repos) *forgepb.Repos { new1 := new(forgepb.Repo) @@ -110,3 +111,4 @@ func testMemoryCorruption(all *forgepb.Repos) *forgepb.Repos { fmt.Println("packages are:", len(all.Repos)) return all } +*/ diff --git a/repo.proto b/repo.proto index 4e07d79..4b087b4 100644 --- a/repo.proto +++ b/repo.proto @@ -11,15 +11,15 @@ import "google/protobuf/timestamp.proto"; // Import the well-known type for Time // for example 'zookeeper' is packaged as 'zookeeper-go' // due to the prior apache foundation project. This happens and is ok! message Repo { - string name = 1; - string version = 2; - string masterBranch = 3; // git 'main' or 'master' branch name - string develBranch = 4; // whatever the git 'devel' branch name is - string userBranch = 5; // whatever your username branch is - bool readonly = 6; // if you have write access to the repo - bool private = 7; // if the repo can be published - string debname = 8; // this is the actual .deb name of the package - string goPath = 9; // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo" + string goPath = 1; // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo" + bool writable = 2; // if you have write access to the repo + bool readOnly = 3; // the opposite, but needed for now because I don't know what I'm doing + bool private = 4; // if the repo can be published + bool directory = 5; // everything in this directory should use these writable & private values + string masterBranch = 6; // git 'main' or 'master' branch name + string develBranch = 7; // whatever the git 'devel' branch name is + string userBranch = 8; // whatever your username branch is + string debname = 9; // this is the actual .deb name of the package google.protobuf.Timestamp verstamp = 10; // the git commit timestamp of the version } diff --git a/repos.go b/repos.go index 4222ab9..5340e62 100644 --- a/repos.go +++ b/repos.go @@ -61,22 +61,22 @@ func (r *Repos) All() *RepoIterator { return iterator } -func (r *Repos) SortByName() *RepoIterator { +func (r *Repos) SortByPath() *RepoIterator { packs := r.selectAllRepos() - sort.Sort(ByRepoName(packs)) + sort.Sort(ByRepoPath(packs)) iterator := NewRepoIterator(packs) return iterator } -// enforces no duplicate repo names +// enforces no duplicate repo paths func (r *Repos) Append(newP *Repo) bool { reposLock.Lock() defer reposLock.Unlock() for _, p := range r.Repos { - if p.Name == newP.Name { + if p.GoPath == newP.GoPath { return false } } @@ -91,13 +91,13 @@ func (r *Repo) Age(newP *Repo) time.Duration { return t } -// find a repo by name -func (r *Repos) FindByName(name string) *Repo { +// find a repo by path +func (r *Repos) FindByPath(gopath string) *Repo { reposLock.RLock() defer reposLock.RUnlock() for _, p := range r.Repos { - if p.Name == name { + if p.GoPath == gopath { return p } } @@ -112,20 +112,20 @@ func (r *Repos) Len() int { return len(r.Repos) } -type ByRepoName []*Repo +type ByRepoPath []*Repo -func (a ByRepoName) Len() int { return len(a) } -func (a ByRepoName) Less(i, j int) bool { return a[i].Name < a[j].Name } -func (a ByRepoName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a ByRepoPath) Len() int { return len(a) } +func (a ByRepoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath } +func (a ByRepoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] } -func (all *Repos) DeleteByName(name string) *Repo { +func (all *Repos) DeleteByPath(gopath string) *Repo { reposLock.Lock() defer reposLock.Unlock() var newr Repo for i, _ := range all.Repos { - if all.Repos[i].Name == name { + if all.Repos[i].GoPath == gopath { newr = *all.Repos[i] all.Repos[i] = all.Repos[len(all.Repos)-1] all.Repos = all.Repos[:len(all.Repos)-1] diff --git a/sampleConfig.go b/sampleConfig.go index b849468..39e47bf 100644 --- a/sampleConfig.go +++ b/sampleConfig.go @@ -8,55 +8,55 @@ import ( func (all *Repos) SampleConfig() { new1 := new(Repo) - new1.Name = "bash" - new1.Version = "5.2.21" + new1.GoPath = "go.wit.com" + new1.Writable = true + new1.Directory = true if all.Append(new1) { - log.Info("added", new1.Name, "ok") + log.Info("added", new1.GoPath, "ok") } else { - log.Info("added", new1.Name, "failed") + log.Info("added", new1.GoPath, "failed") } new1 = new(Repo) - new1.Name = "zookeeper" + new1.GoPath = "go.wit.com/apps/zookeeper" new1.Debname = "zookeeper-go" if all.Append(new1) { - log.Info("added", new1.Name, "ok") + log.Info("added", new1.GoPath, "ok") } else { - log.Info("added", new1.Name, "failed") + log.Info("added", new1.GoPath, "failed") } new1 = new(Repo) - new1.Name = "wit-package" + new1.GoPath = "go.wit.com/apps/wit-package" new1.Private = true if all.Append(new1) { - log.Info("added", new1.Name, "ok") + log.Info("added", new1.GoPath, "ok") } else { - log.Info("added", new1.Name, "failed") + log.Info("added", new1.GoPath, "failed") } new1 = new(Repo) - new1.Name = "networkQuality" + new1.GoPath = "go.wit.com/apps/networkQuality" new1.Debname = "networkquality" - new1.Readonly = true + new1.ReadOnly = true if all.Append(new1) { - log.Info("added", new1.Name, "ok") + log.Info("added", new1.GoPath, "ok") } else { - log.Info("added", new1.Name, "failed") + log.Info("added", new1.GoPath, "failed") } new2 := new(Repo) - new2.Name = "go-clone" - new2.Version = "0.6.8" // good version of the macos + new2.GoPath = "go.wit.com/apps/go-clone" if all.Append(new2) { - log.Info("added", new2.Name, "ok") + log.Info("added", new2.GoPath, "ok") } else { - log.Info("added", new2.Name, "failed") + log.Info("added", new2.GoPath, "failed") } if all.Append(new2) { - log.Info("added", new2.Name, "ok (this is bad)") + log.Info("added", new2.GoPath, "ok (this is bad)") } else { - log.Info("added", new2.Name, "failed (but ok)") + log.Info("added", new2.GoPath, "failed (but ok)") } fmt.Println("first time user. adding an example config file with", len(all.Repos), "repos") diff --git a/update.go b/update.go index f1f1af3..8dce1a0 100644 --- a/update.go +++ b/update.go @@ -1,7 +1,7 @@ package forgepb func (all *Repos) UpdateGoPath(name string, gopath string) bool { - oldr := all.DeleteByName(name) + oldr := all.DeleteByPath(name) if oldr == nil { // nothing to update return false