backend: Don't watch symlinks nor temporary directories

This commit is contained in:
nemunaire 2018-01-21 14:03:55 +01:00
parent b8f573ce86
commit 191c89f7ad

View File

@ -30,7 +30,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" {
if d.IsDir() && d.Name() != ".tmp" && d.Mode() & os.ModeSymlink == 0 {
if err := watchsubdir(watcher, p); err != nil {
return err
}
@ -113,12 +113,12 @@ func main() {
for {
select {
case ev := <-watcher.Events:
if d, err := os.Stat(ev.Name); err == nil && d.IsDir() && ev.Op & fsnotify.Create == fsnotify.Create {
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 {
} else if ev.Op & watchedNotify == watchedNotify && d.Mode().IsRegular() {
if *debugINotify {
log.Println("Treating event:", ev, "for", ev.Name)
}