mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
refactor event parsing
This commit is contained in:
@@ -97,19 +97,26 @@ func (i *Inotify) ParseNextEvent(buf []byte) (*Event, uint32, error) {
|
|||||||
return nil, offset, fmt.Errorf("unknown watcher ID: %d", sys.Wd)
|
return nil, offset, fmt.Errorf("unknown watcher ID: %d", sys.Wd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &Event{
|
||||||
|
Name: getEventName(watcher, sys, buf, offset),
|
||||||
|
Op: getEventOp(sys),
|
||||||
|
}, offset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEventName(watcher *Watcher, sys *unix.InotifyEvent, buf []byte, offset uint32) string {
|
||||||
name := watcher.Dir + "/"
|
name := watcher.Dir + "/"
|
||||||
if sys.Len > 0 && len(buf) >= int(offset) {
|
if sys.Len > 0 && len(buf) >= int(offset) {
|
||||||
name += string(bytes.TrimRight(buf[unix.SizeofInotifyEvent:offset], "\x00"))
|
name += string(bytes.TrimRight(buf[unix.SizeofInotifyEvent:offset], "\x00"))
|
||||||
}
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEventOp(sys *unix.InotifyEvent) string {
|
||||||
op, ok := InotifyEvents[sys.Mask]
|
op, ok := InotifyEvents[sys.Mask]
|
||||||
if !ok {
|
if !ok {
|
||||||
op = strconv.FormatInt(int64(sys.Mask), 2)
|
op = strconv.FormatInt(int64(sys.Mask), 2)
|
||||||
}
|
}
|
||||||
|
return op
|
||||||
return &Event{
|
|
||||||
Name: name,
|
|
||||||
Op: op,
|
|
||||||
}, offset, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Inotify) Close() error {
|
func (i *Inotify) Close() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user