mirror of
https://github.com/go-task/task.git
synced 2025-04-17 12:06:30 +02:00
Update watch.go
Watch: Stop removing and addings files all the time.
This commit is contained in:
parent
9b2e25735b
commit
d261a986ab
21
watch.go
21
watch.go
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -41,6 +42,7 @@ func (e *Executor) watchTasks(calls ...taskfile.Call) error {
|
|||||||
defer w.Close()
|
defer w.Close()
|
||||||
w.SetMaxEvents(1)
|
w.SetMaxEvents(1)
|
||||||
if err := w.Ignore(watchIgnoredDirs...); err != nil {
|
if err := w.Ignore(watchIgnoredDirs...); err != nil {
|
||||||
|
cancel()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,12 +116,6 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Ca
|
|||||||
oldWatchedFiles[f] = struct{}{}
|
oldWatchedFiles[f] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for f := range oldWatchedFiles {
|
|
||||||
if err := w.Remove(f); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var registerTaskFiles func(taskfile.Call) error
|
var registerTaskFiles func(taskfile.Call) error
|
||||||
registerTaskFiles = func(c taskfile.Call) error {
|
registerTaskFiles = func(c taskfile.Call) error {
|
||||||
task, err := e.CompiledTask(c)
|
task, err := e.CompiledTask(c)
|
||||||
@ -146,12 +142,17 @@ func (e *Executor) registerWatchedFiles(w *watcher.Watcher, calls ...taskfile.Ca
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if _, ok := oldWatchedFiles[f]; ok {
|
absFile, err := filepath.Abs(f)
|
||||||
continue
|
if err != nil {
|
||||||
}
|
|
||||||
if err := w.Add(f); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if _, ok := oldWatchedFiles[absFile]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := w.Add(absFile); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
e.Logger.VerboseOutf(logger.Green, "task: watching new file: %v", absFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user