Created
March 11, 2013 19:43
-
-
Save nbkolchin/5137058 to your computer and use it in GitHub Desktop.
MacOSX bug demo.
This file contains 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 ( | |
"log" | |
"os" | |
"github.com/howeyc/fsnotify" | |
) | |
func main() { | |
c := make(chan int) | |
if len(os.Args) < 2 { | |
log.Fatal("no arguments") | |
} | |
n, err := fsnotify.NewWatcher() | |
if err != nil { | |
log.Fatal(err) | |
} | |
go func() { | |
for { | |
select { | |
case ev := <-n.Event: | |
log.Println("event:", ev) | |
if ev.IsCreate() { | |
log.Println("removing", ev.Name) | |
err = os.Remove(ev.Name) | |
if err != nil { | |
log.Println("remove failed:", err) | |
} | |
} | |
case err := <-n.Error: | |
log.Println("error:", err) | |
} | |
} | |
}() | |
for _, s := range os.Args[1:] { | |
err = n.WatchFlags(s, fsnotify.FSN_CREATE) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} | |
<-c // wait forever | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment