Created
February 14, 2013 22:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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