Skip to content

run_watch patterns match filesystem events from unrelated watchers after prefix-stripping #3222

@jskrill

Description

@jskrill

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+"/")
}

  1. patternsSplitted becomes ["", "var", "tmp", "chart", "**"]
  2. lastIndex becomes 4
  3. targetPath be becomes /var/tmp/chart
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions