diff options
| author | Jeff Carr <[email protected]> | 2024-11-04 02:14:54 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-04 02:14:54 -0600 |
| commit | 98926bf2f80a25e51429d74182254da1103bdbc7 (patch) | |
| tree | 15f7dba8217d883411e212b0ee8db4f490b9a244 /scanIterator.go | |
| parent | 8c415947df3ed66ec4207266b457136e30263568 (diff) | |
ignore new repos until init()
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'scanIterator.go')
| -rw-r--r-- | scanIterator.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/scanIterator.go b/scanIterator.go new file mode 100644 index 0000000..4214014 --- /dev/null +++ b/scanIterator.go @@ -0,0 +1,77 @@ +package repolist + +import ( + "fmt" + "os" +) + +type RepoIterator struct { + repos []*RepoRow + index int +} + +// NewRepoIterator initializes a new iterator. +func NewRepoIterator(repos []*RepoRow) *RepoIterator { + return &RepoIterator{repos: repos} +} + +// Scan moves to the next element and returns false if there are no more repos. +func (it *RepoIterator) Scan() bool { + if it.index >= len(it.repos) { + return false + } + it.index++ + return true +} + +// Repo returns the current repo. +func (it *RepoIterator) Repo() *RepoRow { + if it.repos[it.index-1] == nil { + for i, d := range it.repos { + fmt.Println("i =", i, d) + } + fmt.Println("len =", len(it.repos)) + fmt.Println("repo == nil", it.index, it.index-1) + os.Exit(-1) + } + return it.repos[it.index-1] +} + +// Use Scan() in a loop, similar to a while loop +// +// for iterator.Scan() { +// d := iterator.Repo() +// fmt.Println("Repo UUID:", d.Uuid) +// } + +func (r *RepoList) ReposAll() *RepoIterator { + repoPointers := r.selectRepoAll() + + iterator := NewRepoIterator(repoPointers) + + return iterator +} + +// SelectRepoPointers safely returns a slice of pointers to Repo records. +func (r *RepoList) selectRepoAll() []*RepoRow { + r.RLock() + defer r.RUnlock() + + // Create a new slice to hold pointers to each Repo + // repoPointers := make([]*Repo, len(c.E.Repos)) + var repoPointers []*RepoRow + for _, repo := range me.allrepos { + if repo == nil { + continue + } + if repo.Status == nil { + continue + } + if ! repo.Status.InitOk { + continue + } + repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration + } + + return repoPointers +} |
