mirror of
https://github.com/beego/bee.git
synced 2024-11-22 05:00:54 +00:00
Merge pull request #214 from amrfaissal/hotfix-212
Ignore tmp/backup files while using watcher
This commit is contained in:
commit
146200024c
31
watch.go
31
watch.go
@ -17,14 +17,14 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/howeyc/fsnotify"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/howeyc/fsnotify"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -47,8 +47,8 @@ func NewWatcher(paths []string, files []string, isgenerate bool) {
|
||||
case e := <-watcher.Event:
|
||||
isbuild := true
|
||||
|
||||
// Skip TMP files for Sublime Text.
|
||||
if checkTMPFile(e.Name) {
|
||||
// Skip ignored files
|
||||
if shouldIgnoreFile(e.Name) {
|
||||
continue
|
||||
}
|
||||
if !checkIfWatchExt(e.Name) {
|
||||
@ -230,15 +230,30 @@ func Start(appname string) {
|
||||
started <- true
|
||||
}
|
||||
|
||||
// checkTMPFile returns true if the event was for TMP files.
|
||||
func checkTMPFile(name string) bool {
|
||||
if strings.HasSuffix(strings.ToLower(name), ".tmp") {
|
||||
return true
|
||||
// Should ignore filenames generated by
|
||||
// Emacs, Vim or SublimeText
|
||||
func shouldIgnoreFile(filename string) bool {
|
||||
for _, regex := range ignoredFilesRegExps {
|
||||
r, err := regexp.Compile(regex)
|
||||
if err != nil {
|
||||
panic("Could not compile the regex: " + regex)
|
||||
}
|
||||
if r.MatchString(filename) {
|
||||
return true
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var watchExts = []string{".go"}
|
||||
var ignoredFilesRegExps = []string{
|
||||
`.#(\w+).go`,
|
||||
`.(\w+).go.swp`,
|
||||
`(\w+).go~`,
|
||||
`(\w+).tmp`,
|
||||
}
|
||||
|
||||
// checkIfWatchExt returns true if the name HasSuffix <watch_ext>.
|
||||
func checkIfWatchExt(name string) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user