-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
51 lines (44 loc) · 1.01 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"log"
"github.com/pablodz/inotifywaitgo/inotifywaitgo"
)
func main() {
dir := "./"
events := make(chan inotifywaitgo.FileEvent)
errors := make(chan error)
go inotifywaitgo.WatchPath(&inotifywaitgo.Settings{
Dir: dir,
FileEvents: events,
ErrorChan: errors,
Options: &inotifywaitgo.Options{
Recursive: true,
Events: []inotifywaitgo.EVENT{
inotifywaitgo.CLOSE_WRITE,
},
Monitor: true,
},
Verbose: true,
})
loopFiles:
for {
select {
case event := <-events:
// For each file close_write event usually there are 2 events,
// is recommended to test inotifywait first
log.Printf("[Event]%s, %v\n", event.Filename, event.Events)
for _, e := range event.Events {
switch e {
case inotifywaitgo.CLOSE_WRITE:
fmt.Printf("File %s close_write\n", event.Filename)
case inotifywaitgo.CLOSE:
fmt.Printf("File %s closed\n", event.Filename)
}
}
case err := <-errors:
fmt.Printf("Error: %s\n", err)
break loopFiles
}
}
}