mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
restructure inotify package and add some tests
This commit is contained in:
23
internal/inotify/observer.go
Normal file
23
internal/inotify/observer.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user