From 45a297a8e526094e8fce6e2c5c0fd89b381d1765 Mon Sep 17 00:00:00 2001 From: ewy Date: Tue, 14 Apr 2026 16:37:17 +0200 Subject: i have to commit at some point! --- model/new.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 model/new.go (limited to 'model/new.go') diff --git a/model/new.go b/model/new.go new file mode 100644 index 0000000..f26bc8f --- /dev/null +++ b/model/new.go @@ -0,0 +1,45 @@ +package model + +import ( + "io/fs" + "path/filepath" + "pik/identity" + "strings" +) + +func NewState(f fs.FS, locations []string, indexers []Indexer, runners []Runner) (*State, error) { + st := &State{} + for _, loc := range locations { + _, dirName := filepath.Split(loc) + src := &Source{ + Path: loc, + Identity: identity.New(dirName), + } + loc = strings.TrimSuffix(loc, "/") + loc = strings.TrimPrefix(loc, "/") + + if loc == "" { + continue + } + + for _, indexer := range indexers { + + s, err := fs.Sub(f, loc) + if err != nil { + return nil, err + } + targets, err := indexer.Index("/"+loc, s, runners) + if err != nil { + return nil, err + } + src.Targets = append(src.Targets, targets...) + } + + if src.Targets != nil { + st.Sources = append(st.Sources, src) + } + + } + + return st, nil +} -- cgit v1.3