evdist: Fix some segv
This commit is contained in:
parent
7a5c1eeba7
commit
e922171f17
@ -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 {
|
||||
|
@ -71,6 +71,30 @@ func (l *distList) AddEvent(nsf *settings.NextSettingsFile) {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *distList) DelEvent(id int64) {
|
||||
l.Lock.Lock()
|
||||
|
||||
istop := len(l.List)
|
||||
for i, n := range l.List {
|
||||
if n.Id == id {
|
||||
istop = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if istop == len(l.List)-1 {
|
||||
l.List = l.List[:istop]
|
||||
} else if istop != len(l.List) {
|
||||
l.List = append(l.List[:istop], l.List[istop+1:]...)
|
||||
}
|
||||
|
||||
l.Lock.Unlock()
|
||||
|
||||
if istop == 0 {
|
||||
l.ResetTimer()
|
||||
}
|
||||
}
|
||||
|
||||
func (l *distList) ResetTimer() {
|
||||
l.Lock.RLock()
|
||||
defer l.Lock.RUnlock()
|
||||
|
Loading…
Reference in New Issue
Block a user