Skip to content

Commit 927a10c

Browse files
committed
refactor(processor): replace filepath.Glob with doublestar.Glob for enhanced pattern matching
- Replaced `filepath.Glob` with `doublestar.Glob` to support advanced glob patterns (e.g., `**/*.py` for recursive matching). Signed-off-by: Yang Kaiyong <yangkaiyong.yky@antgroup.com>
1 parent 91df4e6 commit 927a10c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/VividCortex/ewma v1.2.0 // indirect
2626
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
2727
github.com/beorn7/perks v1.0.1 // indirect
28+
github.com/bmatcuk/doublestar/v4 v4.8.1
2829
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2930
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3031
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
1010
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
1111
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
1212
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
13+
github.com/bmatcuk/doublestar/v4 v4.8.1 h1:54Bopc5c2cAvhLRAzqOGCYHYyhcDHsFF4wWIR5wKP38=
14+
github.com/bmatcuk/doublestar/v4 v4.8.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
1315
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
1416
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
1517
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=

pkg/backend/processor/base.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ package processor
1919
import (
2020
"context"
2121
"fmt"
22+
"os"
2223
"path/filepath"
2324
"sort"
2425
"sync"
2526
"sync/atomic"
2627

2728
"github.com/CloudNativeAI/modctl/pkg/backend/build"
2829
"github.com/CloudNativeAI/modctl/pkg/storage"
30+
doublestar "github.com/bmatcuk/doublestar/v4"
2931

3032
"github.com/chelnak/ysmrr"
3133
humanize "github.com/dustin/go-humanize"
@@ -58,11 +60,14 @@ func (b *base) Process(ctx context.Context, workDir, repo string, opts ...Option
5860

5961
var matchedPaths []string
6062
for _, pattern := range b.patterns {
61-
matches, err := filepath.Glob(filepath.Join(absWorkDir, pattern))
63+
matches, err := doublestar.Glob(os.DirFS(absWorkDir), pattern)
6264
if err != nil {
6365
return nil, err
6466
}
65-
67+
// convert to absolute paths
68+
for i := range matches {
69+
matches[i] = filepath.Join(absWorkDir, matches[i])
70+
}
6671
matchedPaths = append(matchedPaths, matches...)
6772
}
6873

0 commit comments

Comments
 (0)