Beispiel #1
0
// Find implements a method of kcd.Reader.
func (db DB) Find(ctx context.Context, filter *kcd.FindFilter, f func(string) error) error {
	cf, err := filter.Compile()
	if err != nil {
		return err
	} else if cf == nil {
		return nil
	}

	// Since index packs don't persist index data, we'll assume any revision
	// and corpus match.
	return db.Archive.ReadUnits(ctx, db.FormatKey, func(digest string, v interface{}) error {
		unit, ok := db.Convert(v)
		if !ok {
			log.Printf("WARNING: Unknown compilation unit type %T (%s)", v, digest)
			return nil // nothing to do here
		}
		idx := unit.Index()
		if cf.LanguageMatches(idx.Language) &&
			cf.TargetMatches(idx.Target) &&
			cf.OutputMatches(idx.Output) &&
			cf.SourcesMatch(idx.Sources...) {

			return f(digest)
		}
		return nil
	})
}
Beispiel #2
0
// Find implements a method of kcd.Reader.
func (db DB) Find(_ context.Context, filter *kcd.FindFilter, f func(string) error) error {
	cf, err := filter.Compile()
	if err != nil {
		return err
	} else if cf == nil {
		return nil
	}

	for digest, index := range db.Index {
		if cf.RevisionMatches(index[RevisionKey]...) &&
			cf.CorpusMatches(index[CorpusKey]...) &&
			cf.LanguageMatches(index[LanguageKey]...) &&
			cf.TargetMatches(index[TargetKey]...) &&
			cf.OutputMatches(index[OutputKey]...) &&
			cf.SourcesMatch(index[SourceKey]...) {

			if err := f(digest); err != nil {
				return err
			}
		}
	}
	return nil
}