Skip to content

Commit

Permalink
introduce watch.include
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Feb 28, 2025
1 parent 876ecc4 commit 8d9e288
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/compose/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (s *composeService) Watch(ctx context.Context, project *types.Project, serv

type watchRule struct {
types.Trigger
include watch.PathMatcher
ignore watch.PathMatcher
service string
}
Expand All @@ -90,6 +91,15 @@ func (r watchRule) Matches(event watch.FileEvent) *sync.PathMapping {
if !pathutil.IsChild(r.Path, hostPath) {
return nil
}
included, err := r.include.Matches(hostPath)
if err != nil {
logrus.Warnf("error include matching %q: %v", hostPath, err)
return nil
}
if !included {
logrus.Debugf("%s is not matching include pattern", hostPath)
return nil
}
isIgnored, err := r.ignore.Matches(hostPath)
if err != nil {
logrus.Warnf("error ignore matching %q: %v", hostPath, err)
Expand Down Expand Up @@ -244,8 +254,19 @@ func getWatchRules(config *types.DevelopConfig, service types.ServiceConfig) ([]
return nil, err
}

var include watch.PathMatcher
if len(trigger.Include) == 0 {
include = watch.AnyMatcher{}
} else {
include, err = watch.NewDockerPatternMatcher(trigger.Path, trigger.Include)
if err != nil {
return nil, err
}
}

rules = append(rules, watchRule{
Trigger: trigger,
include: include,
ignore: watch.NewCompositeMatcher(
dockerIgnores,
watch.EphemeralPathMatcher(),
Expand Down
9 changes: 9 additions & 0 deletions pkg/watch/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ type PathMatcher interface {
MatchesEntireDir(file string) (bool, error)
}

// AnyMatcher is a PathMatcher to match any path
type AnyMatcher struct{}

func (AnyMatcher) Matches(f string) (bool, error) { return true, nil }
func (AnyMatcher) MatchesEntireDir(f string) (bool, error) { return true, nil }

var _ PathMatcher = AnyMatcher{}

// EmptyMatcher is a PathMatcher to match no path
type EmptyMatcher struct{}

func (EmptyMatcher) Matches(f string) (bool, error) { return false, nil }
Expand Down

0 comments on commit 8d9e288

Please sign in to comment.