Support exclusions again.
This commit is contained in:
parent
f9614ffc48
commit
1809033049
18
dau.go
18
dau.go
@ -88,7 +88,7 @@ func (w *watch) ProcessNewFiles() []string {
|
|||||||
// walk the path
|
// walk the path
|
||||||
err := filepath.WalkDir(w.config.Path,
|
err := filepath.WalkDir(w.config.Path,
|
||||||
func(path string, d fs.DirEntry, err error) error {
|
func(path string, d fs.DirEntry, err error) error {
|
||||||
return w.checkFile(path, &newFiles)
|
return w.checkFile(path, &newFiles, w.config.Exclude)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -116,9 +116,9 @@ func (w *watch) checkPath() bool {
|
|||||||
|
|
||||||
// checkFile checks if a file is eligible, first looking at extension (to
|
// checkFile checks if a file is eligible, first looking at extension (to
|
||||||
// avoid statting files uselessly) then modification times.
|
// avoid statting files uselessly) then modification times.
|
||||||
// If the file is eligble, and new enough to care we add it to the passed in
|
// If the file is eligible, not excluded and new enough to care we add it
|
||||||
// array of files
|
// to the passed in array of files
|
||||||
func (w *watch) checkFile(path string, found *[]string) error {
|
func (w *watch) checkFile(path string, found *[]string, exclusions []string) error {
|
||||||
log.Printf("Considering %s", path)
|
log.Printf("Considering %s", path)
|
||||||
|
|
||||||
extension := strings.ToLower(filepath.Ext(path))
|
extension := strings.ToLower(filepath.Ext(path))
|
||||||
@ -133,7 +133,15 @@ func (w *watch) checkFile(path string, found *[]string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fi.ModTime().After(w.lastCheck) && fi.Mode().IsRegular() {
|
if fi.ModTime().After(w.lastCheck) && fi.Mode().IsRegular() {
|
||||||
*found = append(*found, path)
|
excluded := false
|
||||||
|
for _, exclusion := range exclusions {
|
||||||
|
if strings.Contains(path, exclusion) {
|
||||||
|
excluded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !excluded {
|
||||||
|
*found = append(*found, path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.newLastCheck.Before(fi.ModTime()) {
|
if w.newLastCheck.Before(fi.ModTime()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user