diff --git a/buildqueue/git.go b/buildqueue/git.go index 2ab877b..10c3b2f 100644 --- a/buildqueue/git.go +++ b/buildqueue/git.go @@ -11,7 +11,6 @@ import ( "time" "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/transport/http" ) @@ -20,10 +19,9 @@ const configsFolder = "pika-build-config" func InitGit() error { _, err := git.PlainClone(config.Configs.GitCache, false, &git.CloneOptions{ - URL: config.Configs.Buildrepo, - SingleBranch: true, - ReferenceName: plumbing.ReferenceName(config.Configs.Buildbranch), - Depth: 1, + URL: config.Configs.Buildrepo, + SingleBranch: true, + Depth: 1, Auth: &http.BasicAuth{ Password: config.Configs.GitToken, Username: config.Configs.GitUser, @@ -52,8 +50,7 @@ func ResetAndPull() error { Password: config.Configs.GitToken, Username: config.Configs.GitUser, }, - RemoteName: "origin", - ReferenceName: plumbing.ReferenceName(config.Configs.Buildbranch), + RemoteName: "origin", }) return err } diff --git a/fastmap/fastmap.go b/fastmap/fastmap.go index 0d24c95..4eb6750 100644 --- a/fastmap/fastmap.go +++ b/fastmap/fastmap.go @@ -3,6 +3,7 @@ package fastmap import ( "fmt" "strings" + "sync" "slices" @@ -10,6 +11,7 @@ import ( ) type Fastmap[K comparable, V any] struct { + mu sync.RWMutex idx map[K]int store []fastmapValue[K, V] } @@ -27,6 +29,8 @@ func New[K comparable, V any]() *Fastmap[K, V] { } func (m *Fastmap[K, V]) Set(key K, value V) { + m.mu.Lock() + defer m.mu.Unlock() if _, ok := m.idx[key]; ok { m.store[m.idx[key]].Value = value return @@ -36,6 +40,8 @@ func (m *Fastmap[K, V]) Set(key K, value V) { } func (m *Fastmap[K, V]) Get(key K) (value V, ok bool) { + m.mu.RLock() + defer m.mu.RUnlock() idx, ok := m.idx[key] if !ok { return @@ -44,6 +50,8 @@ func (m *Fastmap[K, V]) Get(key K) (value V, ok bool) { } func (m *Fastmap[K, V]) Delete(key K) { + m.mu.Lock() + defer m.mu.Unlock() idx, ok := m.idx[key] if !ok { return @@ -54,15 +62,21 @@ func (m *Fastmap[K, V]) Delete(key K) { } func (m *Fastmap[K, V]) Has(key K) bool { + m.mu.RLock() + defer m.mu.RUnlock() _, ok := m.idx[key] return ok } func (m *Fastmap[K, V]) Len() int { + m.mu.RLock() + defer m.mu.RUnlock() return len(m.idx) } func (m *Fastmap[K, V]) GetPage(pageNum int, pageSize int) *Fastmap[K, V] { + m.mu.RLock() + defer m.mu.RUnlock() start := pageSize * pageNum end := start + pageSize if end > len(m.store) { @@ -77,11 +91,15 @@ func (m *Fastmap[K, V]) GetPage(pageNum int, pageSize int) *Fastmap[K, V] { } func (m *Fastmap[K, V]) Clear() { + m.mu.Lock() + defer m.mu.Unlock() m.idx = make(map[K]int) m.store = make([]fastmapValue[K, V], 0) } func (m *Fastmap[K, V]) Iter(fn func(key K, value V) bool) { + m.mu.RLock() + defer m.mu.RUnlock() for _, v := range m.store { if !fn(v.Key, v.Value) { break @@ -90,6 +108,8 @@ func (m *Fastmap[K, V]) Iter(fn func(key K, value V) bool) { } func (m *Fastmap[K, V]) StableSortByKey() { + m.mu.Lock() + defer m.mu.Unlock() slices.SortStableFunc(m.store, func(a, b fastmapValue[K, V]) int { aKey := fmt.Sprint(a.Key) bKey := fmt.Sprint(b.Key) @@ -103,6 +123,8 @@ func (m *Fastmap[K, V]) StableSortByKey() { } func (m *Fastmap[K, V]) MarshalText() ([]byte, error) { + m.mu.RLock() + defer m.mu.RUnlock() var builder strings.Builder for _, v := range m.store { builder.WriteString(fmt.Sprintf("%v:%v\n", v.Key, v.Value)) @@ -111,6 +133,8 @@ func (m *Fastmap[K, V]) MarshalText() ([]byte, error) { } func (m *Fastmap[K, V]) UnmarshalText(text []byte) error { + m.mu.Lock() + defer m.mu.Unlock() m.Clear() lines := strings.Split(string(text), "\n") for _, line := range lines { @@ -135,6 +159,8 @@ func (m *Fastmap[K, V]) UnmarshalText(text []byte) error { } func (m *Fastmap[K, V]) MarshalJSON() ([]byte, error) { + m.mu.RLock() + defer m.mu.RUnlock() temp := make(map[K]V) for _, v := range m.store { temp[v.Key] = v.Value @@ -143,6 +169,8 @@ func (m *Fastmap[K, V]) MarshalJSON() ([]byte, error) { } func (m *Fastmap[K, V]) UnmarshalJSON(data []byte) error { + m.mu.Lock() + defer m.mu.Unlock() temp := make(map[K]V) if err := json.Unmarshal(data, &temp); err != nil { return err