From: jaehoon.hyun Date: Wed, 27 Mar 2019 01:03:47 +0000 (+0900) Subject: watcherfs.go add for TDD X-Git-Tag: submit/tizen/20190409.085658~17^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e84303feb09390b934a5c527b69028fcbc2bd54f;p=platform%2Fcore%2Fsystem%2Fedge-orchestration.git watcherfs.go add for TDD --- diff --git a/src/configuremgr/incubator/watcherfs.go b/src/configuremgr/incubator/watcherfs.go new file mode 100644 index 0000000..01d4f40 --- /dev/null +++ b/src/configuremgr/incubator/watcherfs.go @@ -0,0 +1,45 @@ +package main + +import ( + "log" + "github.com/fsnotify/fsnotify" +) + +func main() { + + watcher, err := fsnotify.NewWatcher() + if err != nil { + log.Fatal(err) + } + defer watcher.Close() + + done := make(chan bool) + go func() { + for { + select { + case event, ok := <-watcher.Events: + log.Println("log event:", event) + + if !ok { + return + } + if event.Op&fsnotify.Write == fsnotify.Write { + log.Println("modified file:", event.Name) + } + case err, ok := <-watcher.Errors: + if !ok { + return + } + log.Println("error:", err) + // default: + // fmt.Println("default") + } + } + }() + + err = watcher.Add("/tmp/foo") + if err != nil { + log.Fatal(err) + } + <-done +} \ No newline at end of file