backend: multithread generation

This commit is contained in:
nemunaire 2019-07-11 19:52:13 +02:00
parent 3bcac39f5f
commit 2b75287d16
7 changed files with 115 additions and 71 deletions

View file

@ -31,7 +31,7 @@ func watchsubdir(watcher *fsnotify.Watcher, pathname string) error {
} else {
for _, d := range ds {
p := path.Join(pathname, d.Name())
if d.IsDir() && d.Name() != ".tmp" && d.Mode() & os.ModeSymlink == 0 {
if d.IsDir() && d.Name() != ".tmp" && d.Mode()&os.ModeSymlink == 0 {
if err := watchsubdir(watcher, p); err != nil {
return err
}
@ -129,17 +129,17 @@ func main() {
for {
select {
case ev := <-watcher.Events:
if d, err := os.Lstat(ev.Name); err == nil && ev.Op & fsnotify.Create == fsnotify.Create && d.Mode().IsDir() && d.Mode() & os.ModeSymlink == 0 && d.Name() != ".tmp" {
if d, err := os.Lstat(ev.Name); err == nil && ev.Op&fsnotify.Create == fsnotify.Create && d.Mode().IsDir() && d.Mode()&os.ModeSymlink == 0 && d.Name() != ".tmp" {
// Register new subdirectory
if err := watchsubdir(watcher, ev.Name); err != nil {
log.Println(err)
}
} else if ev.Op & watchedNotify == watchedNotify && d.Mode().IsRegular() {
} else if ev.Op&watchedNotify == watchedNotify && d.Mode().IsRegular() {
if *debugINotify {
log.Println("Treating event:", ev, "for", ev.Name)
}
go treat(ev.Name)
} else if ev.Op & fsnotify.Write == fsnotify.Write {
} else if 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 {