From 704d06ba87ac8bc4af4abc1ed88efed82df7127d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 20 Nov 2024 15:57:34 -0600 Subject: UpdateGoPath() (probably without memory corruption) --- repos.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'repos.go') diff --git a/repos.go b/repos.go index 07ee8e2..4222ab9 100644 --- a/repos.go +++ b/repos.go @@ -118,6 +118,23 @@ 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 (all *Repos) DeleteByName(name string) *Repo { + reposLock.Lock() + defer reposLock.Unlock() + + var newr Repo + + for i, _ := range all.Repos { + if all.Repos[i].Name == name { + newr = *all.Repos[i] + all.Repos[i] = all.Repos[len(all.Repos)-1] + all.Repos = all.Repos[:len(all.Repos)-1] + return &newr + } + } + return nil +} + // safely returns a slice of pointers to the Repo protobufs func (r *Repos) selectAllRepos() []*Repo { reposLock.RLock() -- cgit v1.2.3