added mutex to sync

This commit is contained in:
2026-05-26 09:23:43 -06:00
parent 8e54235cfe
commit f13f8bd8b8
+9 -3
View File
@@ -5,6 +5,7 @@ import (
"log/slog" "log/slog"
"os" "os"
"path/filepath" "path/filepath"
"sync"
"github.com/ewpt3ch/pkgstash/internal/cache" "github.com/ewpt3ch/pkgstash/internal/cache"
) )
@@ -21,9 +22,10 @@ type CacheClient interface {
} }
type RepoSync struct { type RepoSync struct {
c CacheClient c CacheClient
root *os.Root root *os.Root
repos []string repos []string
syncMu sync.Mutex
} }
func NewRepoSync(c CacheClient, path string, repos []string) (*RepoSync, error) { func NewRepoSync(c CacheClient, path string, repos []string) (*RepoSync, error) {
@@ -40,6 +42,10 @@ func NewRepoSync(c CacheClient, path string, repos []string) (*RepoSync, error)
} }
func (r *RepoSync) Sync() error { func (r *RepoSync) Sync() error {
if !r.syncMu.TryLock() {
return nil
}
defer r.syncMu.Unlock()
for _, repo := range r.repos { for _, repo := range r.repos {
// create map of pkgname to filenames from current db // create map of pkgname to filenames from current db