From f13f8bd8b8d23d8ecc3da6415e0e855542709bee Mon Sep 17 00:00:00 2001 From: Eric Phillips Date: Tue, 26 May 2026 09:23:43 -0600 Subject: [PATCH] added mutex to sync --- internal/repomaint/repomaint.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/repomaint/repomaint.go b/internal/repomaint/repomaint.go index f2194c8..1da94c8 100644 --- a/internal/repomaint/repomaint.go +++ b/internal/repomaint/repomaint.go @@ -5,6 +5,7 @@ import ( "log/slog" "os" "path/filepath" + "sync" "github.com/ewpt3ch/pkgstash/internal/cache" ) @@ -21,9 +22,10 @@ type CacheClient interface { } type RepoSync struct { - c CacheClient - root *os.Root - repos []string + c CacheClient + root *os.Root + repos []string + syncMu sync.Mutex } 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 { + if !r.syncMu.TryLock() { + return nil + } + defer r.syncMu.Unlock() for _, repo := range r.repos { // create map of pkgname to filenames from current db