ephemeral.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package watch
  14. // EphemeralPathMatcher filters out spurious changes that we don't want to
  15. // rebuild on, like IDE temp/lock files.
  16. //
  17. // This isn't an ideal solution. In an ideal world, the user would put
  18. // everything to ignore in their tiltignore/dockerignore files. This is a
  19. // stop-gap so they don't have a terrible experience if those files aren't
  20. // there or aren't in the right places.
  21. //
  22. // NOTE: The underlying `patternmatcher` is NOT always Goroutine-safe, so
  23. // this is not a singleton; we create an instance for each watcher currently.
  24. func EphemeralPathMatcher() PathMatcher {
  25. golandPatterns := []string{"**/*___jb_old___", "**/*___jb_tmp___", "**/.idea/**"}
  26. emacsPatterns := []string{"**/.#*", "**/#*#"}
  27. // if .swp is taken (presumably because multiple vims are running in that dir),
  28. // vim will go with .swo, .swn, etc, and then even .svz, .svy!
  29. // https://github.com/vim/vim/blob/ea781459b9617aa47335061fcc78403495260315/src/memline.c#L5076
  30. // ignoring .sw? seems dangerous, since things like .swf or .swi exist, but ignoring the first few
  31. // seems safe and should catch most cases
  32. vimPatterns := []string{"**/4913", "**/*~", "**/.*.swp", "**/.*.swx", "**/.*.swo", "**/.*.swn"}
  33. // kate (the default text editor for KDE) uses a file similar to Vim's .swp
  34. // files, but it doesn't have the "incrememnting" character problem mentioned
  35. // above
  36. katePatterns := []string{"**/.*.kate-swp"}
  37. // go stdlib creates tmpfiles to determine umask for setting permissions
  38. // during file creation; they are then immediately deleted
  39. // https://github.com/golang/go/blob/0b5218cf4e3e5c17344ea113af346e8e0836f6c4/src/cmd/go/internal/work/exec.go#L1764
  40. goPatterns := []string{"**/*-go-tmp-umask"}
  41. var allPatterns []string
  42. allPatterns = append(allPatterns, golandPatterns...)
  43. allPatterns = append(allPatterns, emacsPatterns...)
  44. allPatterns = append(allPatterns, vimPatterns...)
  45. allPatterns = append(allPatterns, katePatterns...)
  46. allPatterns = append(allPatterns, goPatterns...)
  47. matcher, err := NewDockerPatternMatcher("/", allPatterns)
  48. if err != nil {
  49. panic(err)
  50. }
  51. return matcher
  52. }