// ChecklistsFromDir reads all of the files in the path and parses their utf8 // encoded json data, turning it into a checklist struct. func ChecklistsFromDir(dirpath string) (chklsts []Checklist, err error) { log.Debug("Creating checklist(s) from " + dirpath) paths := chkutil.GetFilesWithExtension(dirpath, ".json") // send one checklist per path to the channel /* out := make(chan Checklist) errs := make(chan error) for _, path := range paths { go func(path string, out chan Checklist, errs chan error) { chklst, err := ChecklistFromFile(path) out <- chklst errs <- err }(path, out, errs) } // get all values from the channel, return them for _ = range paths { err := <-errs if err != nil { return chklsts, err } chklsts = append(chklsts, <-out) } close(out) close(errs) */ for _, path := range paths { chklst, err := ChecklistFromFile(path) if err != nil { return chklsts, err } chklsts = append(chklsts, chklst) } return chklsts, nil }
// getAptrepos constructs repos from the sources.list file at path. Gives // non-zero URLs func getAptRepos() (repos []repo) { // getAptSources returns all the urls of all apt sources (including source // code repositories getAptSources := func() (urls []string) { otherLists := chkutil.GetFilesWithExtension("/etc/apt/sources.list.d", ".list") sourceLists := append([]string{"/etc/apt/sources.list"}, otherLists...) for _, f := range sourceLists { split := tabular.ProbabalisticSplit(chkutil.FileToString(f)) // filter out comments commentRegex := regexp.MustCompile(`^\s*#`) for _, line := range split { if len(line) > 1 && !(commentRegex.MatchString(line[0])) { urls = append(urls, line[1]) } } } return urls } for _, src := range getAptSources() { repos = append(repos, repo{URL: src}) } return repos }