What happened?
When using run_watch and --path DIR/** is combined with any other path, all filesystem events stemming from the root of the secondary path trigger a restart because DIR/** gets stripped to ** which matches any path via doublestar.
In my case, I was trying to watch --path devspace.yaml and --path HELM_CHART_PATH/** because I wanted devspace to reload on helm chart changes and its own config changes.
Taking an example, let's assume HELM_CHART_PATH is /var/tmp/chart and so we have:
--path devspace.yaml
--path /var/tmp/chart/**
In the code at
|
patternsSplitted := strings.Split(filepath.ToSlash(p), "/") |
|
lastIndex := len(patternsSplitted) - 1 |
|
for i, s := range patternsSplitted { |
|
if strings.Contains(s, "*") { |
|
lastIndex = i |
|
break |
|
} |
|
} |
|
|
|
targetPath := strings.Join(patternsSplitted[:lastIndex], "/") |
|
if targetPath == "" { |
|
targetPath = "." |
|
} else { |
|
patterns[i] = strings.TrimPrefix(patterns[i], targetPath+"/") |
|
} |
- patternsSplitted becomes ["", "var", "tmp", "chart", "**"]
- lastIndex becomes 4
- targetPath be becomes /var/tmp/chart
- patterns[i] becomes "**"
patterns gets passed to handleCommand at
|
return w.handleCommand(ctx, patterns, excludes, action, globalChannel) |
Trivially, since ** matches all paths then any path which reaches
|
hasMatched := false |
|
for _, p := range patterns { |
|
hasMatched, _ = doublestar.Match(p, e) |
|
if hasMatched { |
|
break |
|
} |
|
} |
would match and cause a reload.
Taking the second path devspace.yaml, that resolves to a recursive watch on "." due to
All changed relative paths go through a global channel here
|
globalChannel <- filepath.ToSlash(relPath) |
but because of the ** pattern, any path rooted at "." (the entire project directory) would cause a reload, not just devspace.yaml.
What did you expect to happen instead?
run_watch should match the patterns given
How can we reproduce the bug? (as minimally and precisely as possible)
run_watch --path devspace.yaml
--path /var/tmp/chart/**
..
Local Environment:
- DevSpace Version: 6.3.20
- Operating System: linux
- ARCH of the OS: AMD64
Kubernetes Cluster:
- Cloud Provider: k3d
- Kubernetes Version: 1.29.7
What happened?
When using run_watch and --path DIR/** is combined with any other path, all filesystem events stemming from the root of the secondary path trigger a restart because DIR/** gets stripped to ** which matches any path via doublestar.
In my case, I was trying to watch --path devspace.yaml and --path HELM_CHART_PATH/** because I wanted devspace to reload on helm chart changes and its own config changes.
Taking an example, let's assume HELM_CHART_PATH is /var/tmp/chart and so we have:
--path devspace.yaml
--path /var/tmp/chart/**
In the code at
devspace/pkg/devspace/pipeline/engine/basichandler/commands/run_watch.go
Lines 92 to 106 in af83b7e
patterns gets passed to handleCommand at
devspace/pkg/devspace/pipeline/engine/basichandler/commands/run_watch.go
Line 171 in af83b7e
Trivially, since ** matches all paths then any path which reaches
devspace/pkg/devspace/pipeline/engine/basichandler/commands/run_watch.go
Lines 193 to 199 in af83b7e
Taking the second path devspace.yaml, that resolves to a recursive watch on "." due to
devspace/pkg/devspace/pipeline/engine/basichandler/commands/run_watch.go
Line 103 in af83b7e
All changed relative paths go through a global channel here
devspace/pkg/devspace/pipeline/engine/basichandler/commands/run_watch.go
Line 163 in af83b7e
What did you expect to happen instead?
run_watch should match the patterns given
How can we reproduce the bug? (as minimally and precisely as possible)
Local Environment:
Kubernetes Cluster: