diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-07-06 01:14:44 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-07-06 01:15:44 +0200 |
commit | ef24d7980c50f706286d99ab6d80a98af89970e3 (patch) | |
tree | e9de25b9b03dbdc1588690eedfee59e39e3e6d9d /hswg | |
parent | 6228693b224937be379ce94e1a066e4b92e6d71b (diff) | |
download | haven-ef24d7980c50f706286d99ab6d80a98af89970e3.tar.gz haven-ef24d7980c50f706286d99ab6d80a98af89970e3.tar.xz haven-ef24d7980c50f706286d99ab6d80a98af89970e3.zip |
hswg: improve inotify processing
Make sure to read the whole record before checking flags.
Diffstat (limited to 'hswg')
-rw-r--r-- | hswg/main.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/hswg/main.go b/hswg/main.go index 9eaca84..6cec971 100644 --- a/hswg/main.go +++ b/hswg/main.go @@ -334,6 +334,15 @@ func dispatchEvents(dirname string, r io.Reader, ch chan<- *watchEvent) error { return err } + base := make([]byte, e.Len) + if e.Len != 0 { + if n, err := r.Read(base); err != nil { + return err + } else if n < int(e.Len) { + return fmt.Errorf("short read") + } + } + switch { case e.Mask&syscall.IN_IGNORED != 0: return fmt.Errorf("watch removed by kernel") @@ -345,13 +354,6 @@ func dispatchEvents(dirname string, r io.Reader, ch chan<- *watchEvent) error { continue } - base := make([]byte, e.Len) - if n, err := r.Read(base); err != nil { - return err - } else if n < int(e.Len) { - return fmt.Errorf("short read") - } - basename, interesting := string(base[:bytes.IndexByte(base, 0)]), false for _, glob := range globs { if matches, _ := filepath.Match(glob, basename); matches { |