refactors psscanner

This commit is contained in:
Dominic Breuker
2018-03-02 13:59:41 +01:00
parent 9670b85f43
commit 644d65be7b
8 changed files with 150 additions and 116 deletions

View File

@@ -1,20 +0,0 @@
package fswatcher
import (
"fmt"
)
func parseEvents(i Inotify, dataCh chan []byte, eventCh chan string, errCh chan error) {
for buf := range dataCh {
var ptr uint32
for len(buf[ptr:]) > 0 {
event, size, err := i.ParseNextEvent(buf[ptr:])
ptr += size
if err != nil {
errCh <- fmt.Errorf("parsing events: %v", err)
continue
}
eventCh <- fmt.Sprintf("%20s | %s", event.Op, event.Name)
}
}
}

View File

@@ -27,13 +27,13 @@ type FSWatcher struct {
eventSize int
}
func NewFSWatcher() (*FSWatcher, error) {
func NewFSWatcher() *FSWatcher {
return &FSWatcher{
i: inotify.NewInotify(),
w: walker.NewWalker(),
maxWatchers: inotify.MaxWatchers,
eventSize: inotify.EventSize,
}, nil
}
}
func (fs *FSWatcher) Close() {

View File

@@ -1,20 +0,0 @@
package fswatcher
import (
"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, err := i.Read(buf)
if err != nil {
errCh <- err
}
triggerCh <- struct{}{}
bufCopy := make([]byte, n)
copy(bufCopy, buf)
dataCh <- bufCopy
}
}