mirror of
https://github.com/beego/bee.git
synced 2024-11-22 20:20:55 +00:00
Ignore tmp/backup files while using watcher
This fixes #212 and Adds the logic to skip tmp and backup files generated by Emacs, Vim or SublimeText. More RegExps can be added to 'ignoredFilesRegExps' slice in watch.go file.
This commit is contained in:
parent
bccfd667c1
commit
ebb0272bc8
29
watch.go
29
watch.go
@ -17,14 +17,14 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/howeyc/fsnotify"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/howeyc/fsnotify"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -47,8 +47,8 @@ func NewWatcher(paths []string, files []string, isgenerate bool) {
|
|||||||
case e := <-watcher.Event:
|
case e := <-watcher.Event:
|
||||||
isbuild := true
|
isbuild := true
|
||||||
|
|
||||||
// Skip TMP files for Sublime Text.
|
// Skip ignored files
|
||||||
if checkTMPFile(e.Name) {
|
if shouldIgnoreFile(e.Name) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !checkIfWatchExt(e.Name) {
|
if !checkIfWatchExt(e.Name) {
|
||||||
@ -230,15 +230,30 @@ func Start(appname string) {
|
|||||||
started <- true
|
started <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkTMPFile returns true if the event was for TMP files.
|
// Should ignore filenames generated by
|
||||||
func checkTMPFile(name string) bool {
|
// Emacs, Vim or SublimeText
|
||||||
if strings.HasSuffix(strings.ToLower(name), ".tmp") {
|
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
|
return true
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var watchExts = []string{".go"}
|
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>.
|
// checkIfWatchExt returns true if the name HasSuffix <watch_ext>.
|
||||||
func checkIfWatchExt(name string) bool {
|
func checkIfWatchExt(name string) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user