Browse Source

walk: typo

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
master
Vincent Batts 5 years ago
parent
commit
adc978026c
2 changed files with 59 additions and 1 deletions
  1. +1
    -1
      app.go
  2. +58
    -0
      walk.go

+ 1
- 1
app.go View File

@ -12,6 +12,6 @@ func main() {
flag.Parse()
for _, arg := range flag.Args() {
WathPath(arg)
WatchPath(arg)
}
}

+ 58
- 0
walk.go View File

@ -0,0 +1,58 @@
package main
import (
"log"
"github.com/fsnotify/fsnotify"
)
// WatchPath establishes a watch on the provided path
func WatchPath(path string) {
/*
29044 2016-09-21 12:40:21 cd x
29045 2016-09-21 12:40:25 touch file
29046 2016-09-21 12:40:39 rm file
29047 2016-09-21 12:40:42 touch file
29048 2016-09-21 12:40:50 echo farts > file
29049 2016-09-21 12:40:57 rm file
produces:
$ ./sync_pass x
2016/09/21 12:40:25 event: "x/file": CREATE
2016/09/21 12:40:25 event: "x/file": CHMOD
2016/09/21 12:40:39 event: "x/file": REMOVE
2016/09/21 12:40:42 event: "x/file": CREATE
2016/09/21 12:40:42 event: "x/file": CHMOD
2016/09/21 12:40:50 event: "x/file": WRITE
2016/09/21 12:40:50 modified file: x/file
2016/09/21 12:40:50 event: "x/file": WRITE
2016/09/21 12:40:50 modified file: x/file
2016/09/21 12:40:57 event: "x/file": REMOVE
*/
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event := <-watcher.Events:
log.Println("event:", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err := <-watcher.Errors:
log.Println("error:", err)
}
}
}()
err = watcher.Add(path)
if err != nil {
log.Fatal(err)
}
<-done
}