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