restructure inotify package and add some tests

This commit is contained in:
Dominic Breuker
2018-02-25 14:21:16 +01:00
parent f5ca2dad75
commit d1c18d901a
16 changed files with 315 additions and 166 deletions

View File

@@ -0,0 +1,23 @@
package inotify
import (
"fmt"
"golang.org/x/sys/unix"
)
func Observe(i *Inotify, triggerCh chan struct{}, dataCh chan []byte, errCh chan error) {
buf := make([]byte, 5*unix.SizeofInotifyEvent)
for {
n, errno := unix.Read(i.fd, buf)
if n == -1 {
errCh <- fmt.Errorf("reading from inotify fd: errno: %d", errno)
return
}
triggerCh <- struct{}{}
bufCopy := make([]byte, n)
copy(bufCopy, buf)
dataCh <- bufCopy
}
}