mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
refactors psscanner
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user