cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.10.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/discovery/glob.go

55lines · modecode

1package discovery
2
3import (
4 "os"
5 "path/filepath"
6)
7
8func NewGlobFileFinder() GlobFileFinder {
9 return GlobFileFinder{}
10}
11
12type GlobFileFinder struct{}
13
14func (gd GlobFileFinder) Find(pattern ...string) (FileFindResults, error) {
15 results := FileCommits{
16 pathCommits: map[string][]string{},
17 }
18
19 for _, p := range pattern {
20 matches, err := filepath.Glob(p)
21 if err != nil {
22 return nil, err
23 }
24
25 for _, path := range matches {
26 s, err := os.Stat(path)
27 if err != nil {
28 return nil, err
29 }
30 if s.IsDir() {
31 err = filepath.Walk(path,
32 func(path string, info os.FileInfo, err error) error {
33 if err != nil {
34 return err
35 }
36
37 if info.IsDir() {
38 return nil
39 }
40
41 results.pathCommits[path] = nil
42
43 return nil
44 })
45 if err != nil {
46 return nil, err
47 }
48 } else {
49 results.pathCommits[path] = nil
50 }
51 }
52 }
53
54 return results, nil
55}