package model import ( "errors" "io/fs" "path/filepath" "slices" "strings" ) func Include(root fs.FS, st *State, data map[string]*SourceData, indexers []Indexer, runners []Runner) error { for _, s := range st.Sources { if data[s.Path] == nil || data[s.Path].Includes == nil { continue } for _, w := range data[s.Path].Includes { if IsRelative(w) { p, err := filepath.Abs(filepath.Join(s.Path, w)) if err != nil { return err } // check if source is already included for _, maybeSource := range st.Sources { if maybeSource.Path == p { continue } } src, errs := NewSource(root, p, indexers, runners) if len(errs) > 0 { return errors.Join(errs...) } s.Targets = append(s.Targets, src.Targets...) } } } return nil } func Wants(root fs.FS, st *State, data map[string]*SourceData, indexers []Indexer, runners []Runner) error { for i, s := range st.Sources { if data[s.Path] == nil || data[s.Path].Wants == nil { continue } for _, w := range data[s.Path].Wants { if IsRelative(w) { p, err := filepath.Abs(filepath.Join(s.Path, w)) if err != nil { return err } // check if source is already included for _, maybeSource := range st.Sources { if maybeSource.Path == p { continue } } src, errs := NewSource(root, p, indexers, runners) if len(errs) > 0 { return errors.Join(errs...) } st.Sources = slices.Insert(st.Sources, i+1, src) } } } return nil } func IsRelative(path string) bool { return strings.HasPrefix(path, ".") }