Skip to content

Commit 2bc9938

Browse files
committed
use filepath.Glob and filepath.Match
1 parent 5050f46 commit 2bc9938

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require (
1717
github.com/go-openapi/spec v0.19.4 // indirect
1818
github.com/go-redis/redis/v7 v7.2.0
1919
github.com/go-sql-driver/mysql v1.5.0
20-
github.com/gobwas/glob v0.2.3
2120
github.com/golang/snappy v0.0.1 // indirect
2221
github.com/google/gofuzz v1.1.0
2322
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect

pkg/analyze/download.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,17 @@ func (f fileContentProvider) getFileContents(fileName string) ([]byte, error) {
191191
}
192192

193193
func (f fileContentProvider) getChildFileContents(dirName string) (map[string][]byte, error) {
194-
// TODO: walk sub-dirs
195-
// return nil, errors.New("not implemented")
196-
return map[string][]byte{}, nil
194+
files, err := filepath.Glob(filepath.Join(f.rootDir, dirName))
195+
if err != nil {
196+
return nil, errors.Wrapf(err, "invalid glob %q", dirName)
197+
}
198+
fileArr := map[string][]byte{}
199+
for _, filePath := range files {
200+
bytes, err := ioutil.ReadFile(filePath)
201+
if err != nil {
202+
return nil, errors.Wrapf(err, "read %q", filePath)
203+
}
204+
fileArr[filePath] = bytes
205+
}
206+
return fileArr, nil
197207
}

pkg/analyze/text_analyze_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package analyzer
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"strings"
67
"testing"
78

8-
"github.com/gobwas/glob"
99
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
@@ -314,13 +314,8 @@ func Test_textAnalyze(t *testing.T) {
314314
}
315315
}
316316

317-
g, err := glob.Compile(n)
318-
if err != nil {
319-
return nil, err
320-
}
321-
322317
for k, v := range test.files {
323-
if g.Match(k) {
318+
if ok, _ := filepath.Match(n, k); ok {
324319
matching[k] = v
325320
}
326321
}

pkg/preflight/analyze.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package preflight
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"strings"
67

7-
"github.com/gobwas/glob"
88
analyze "github.com/replicatedhq/troubleshoot/pkg/analyze"
99
)
1010

@@ -26,14 +26,8 @@ func (c CollectResult) Analyze() []*analyze.AnalyzeResult {
2626
}
2727
}
2828

29-
g, err := glob.Compile(prefix)
30-
// don't treat this as a true error as glob is a late addition
31-
if err != nil {
32-
return matching, nil
33-
}
34-
3529
for k, v := range c.AllCollectedData {
36-
if g.Match(k) {
30+
if ok, _ := filepath.Match(prefix, k); ok {
3731
matching[k] = v
3832
}
3933
}

0 commit comments

Comments
 (0)