Skip to content

Instantly share code, notes, and snippets.

@pkrnjevic
Created February 14, 2013 22:00
Show Gist options
  • Save pkrnjevic/4956784 to your computer and use it in GitHub Desktop.
Save pkrnjevic/4956784 to your computer and use it in GitHub Desktop.
Slightly modified fsnotify-test.go. In theory this would add newly created directories to the active watcher. In practise, on OS X, it quickly runs out of file resources and crashes.
package main
import (
"github.com/howeyc/fsnotify"
"log"
"os"
)
func ExampleNewWatcher() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
go func() {
for {
select {
case ev := <-watcher.Event:
if ev.IsCreate() {
fn := ev.Name
fi, err := os.Lstat(fn)
if err != nil {
log.Fatal(err)
}
if fi.IsDir() {
err = watcher.Watch(fn)
if err != nil {
log.Fatal(err)
}
log.Println(">>", fn)
}
}
// log.Println("event:", ev)
case err := <-watcher.Error:
log.Println("error:", err)
}
}
}()
err = watcher.Watch("/tmp/foo")
if err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment