added mutex to sync
This commit is contained in:
@@ -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"
|
||||||
)
|
)
|
||||||
@@ -24,6 +25,7 @@ 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
|
||||||
|
|||||||
Reference in New Issue
Block a user