summaryrefslogtreecommitdiff
path: root/model
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-17 00:51:16 +0200
committerewy <ewy0@protonmail.com>2026-04-17 00:51:16 +0200
commit6d77bb49e6a92c38caa99627e33cfd2a600092ac (patch)
tree1708adf1a10a572d537437e7590fa4643405113b /model
parentc00cba98075ecddc82de4690574e06a9fa687ca3 (diff)
prevent shuffling of items after async init
Diffstat (limited to 'model')
-rw-r--r--model/new.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/model/new.go b/model/new.go
index e23bbf6..6f5c71b 100644
--- a/model/new.go
+++ b/model/new.go
@@ -13,13 +13,15 @@ func NewState(f fs.FS, locations []string, indexers []Indexer, runners []Runner)
var errs []error
st := &State{}
wg := sync.WaitGroup{}
- for _, loc := range locations {
+ var sources = make([]*Source, len(locations), len(locations))
+ for i, loc := range locations {
wg.Go(func() {
_, dirName := filepath.Split(loc)
src := &Source{
Path: loc,
Identity: identity.New(dirName),
}
+ sources[i] = src
loc = strings.TrimSuffix(loc, "/")
loc = strings.TrimPrefix(loc, "/")
@@ -28,30 +30,42 @@ func NewState(f fs.FS, locations []string, indexers []Indexer, runners []Runner)
}
myWg := sync.WaitGroup{}
- for _, indexer := range indexers {
+ var targets = make([][]Target, len(indexers), len(indexers))
+ for ti, indexer := range indexers {
myWg.Go(func() {
s, err := fs.Sub(f, loc)
if err != nil && !errors.Is(err, fs.ErrNotExist) {
errs = append(errs, err)
return
}
- targets, err := indexer.Index("/"+loc, s, runners)
+ result, err := indexer.Index("/"+loc, s, runners)
if err != nil && !errors.Is(err, fs.ErrNotExist) {
errs = append(errs, err)
return
}
- src.Targets = append(src.Targets, targets...)
+ targets[ti] = result
})
}
myWg.Wait()
- if src.Targets != nil {
- st.Sources = append(st.Sources, src)
+ for _, t := range targets {
+ if t == nil {
+ continue
+ }
+ sources[i].Targets = append(sources[i].Targets, t...)
}
+
})
}
wg.Wait()
+ for _, s := range sources {
+ if s == nil || s.Targets == nil {
+ continue
+ }
+ st.Sources = append(st.Sources, s)
+ }
+
return st, errs
}