evdist: Fix some segv

This commit is contained in:
nemunaire 2022-06-08 12:31:08 +02:00
commit e922171f17
2 changed files with 36 additions and 3 deletions

View file

@ -89,7 +89,7 @@ func main() {
v, err = settings.ReadNextSettingsFile(path.Join(settings.SettingsDir, fmt.Sprintf("%d.json", v.Id)), v.Id)
if err != nil {
log.Printf("Unable to read %d.json: %s", v.Id, err.Error())
log.Printf("Unable to read json: %s", err.Error())
} else if cur_settings, err := settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
log.Printf("Unable to read settings.json: %s", err.Error())
} else {
@ -110,8 +110,17 @@ func main() {
if *debugINotify {
log.Println("Treating event:", ev, "for", ev.Name)
}
go l.treat(ev.Name)
} else if ev.Op&fsnotify.Write == fsnotify.Write {
l.treat(ev.Name)
} else if err == nil && ev.Op&watchedNotify == fsnotify.Remove && d.Mode().IsRegular() {
if *debugINotify {
log.Println("Treating deletion event:", ev, "for", ev.Name)
}
if ts, err := strconv.ParseInt(strings.TrimSuffix(path.Base(ev.Name), ".json"), 10, 64); err == nil {
log.Println("Unable to parseint", ev.Name, err.Error())
} else {
l.DelEvent(ts)
}
} else if err == nil && ev.Op&fsnotify.Write == fsnotify.Write {
log.Println("FSNOTIFY WRITE SEEN. Prefer looking at them, as it appears files are not atomically moved.")
watchedNotify = fsnotify.Write
} else if *debugINotify {