Skip to content

Commit bd77d61

Browse files
committed
fix segfault on non-existent directories
1 parent c0af824 commit bd77d61

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ func main() {
2727
log.Fatal(err)
2828
}
2929
for _, watchConfig := range config.Watch {
30-
log.Printf("%v", watchConfig)
3130
dirWatcher := watcher.NewWatcher(watchConfig.Name, watchConfig.Paths, watchConfig.Commands)
3231
dirWatcher.Run(needReprint)
3332
watchers = append(watchers, dirWatcher)
3433
}
3534

36-
log.Printf("%d", len(watchers))
37-
3835
var statusPrinter = printer.NewPrinter()
3936
statusPrinter.RegisterWatchers(watchers)
4037
statusPrinter.Start(needReprint)

watcher/watcher.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ type Watcher struct {
2121
func NewWatcher(name string, dirs []string, commands []string) *Watcher {
2222
watcher, _ := fsnotify.NewWatcher()
2323
for _, dir := range dirs {
24+
if _, err := os.Stat(dir); os.IsNotExist(err) {
25+
log.Fatalf("Directory '%s' in '%s' watcher does not exists", dir, name)
26+
}
2427
if err := filepath.Walk(dir, watchDir(watcher)); err != nil {
25-
fmt.Println("ERROR", err)
28+
log.Fatal("ERROR", err)
2629
}
2730
}
2831
return &Watcher{watcher: watcher, commands: commands, name: name, status: "⚪"}
2932
}
3033

3134
func (w *Watcher) Run(needReprint chan bool) {
32-
log.Printf("watcher %s has been started", w.name)
3335
go func() {
3436
f := func() {
3537
w.status = "🔄"

0 commit comments

Comments
 (0)