howeyc/fsnotify

Getting events only once.

Opened this issue · 1 comments

Hi,

I was referring to the below example to get used to this module as I need to watch a repo file and based on events I need to perform certain actions:

Issue:
For testing, I am watching one file "/home/ankit/delta.txt".

The problem is that I receive events only first time if any modification is done to the file /home/ankit/delta.txt but after that I never receive any events, even If I access/remove/modify this file?

Output of my implementation:
2017/06/27 12:02:49 event: "/home/ankit/delta.txt": RENAME
2017/06/27 12:02:49 event: "/home/ankit/delta.txt": MODIFY|ATTRIB
2017/06/27 12:02:49 event: "/home/ankit/delta.txt": DELETE

My OS Details:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.5 LTS"


package main

import (
"log"

"github.com/howeyc/fsnotify"

)

func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}

done := make(chan bool)

// Process events
go func() {
	for {
		select {
		case ev := <-watcher.Event:
			log.Println("event:", ev)
		case err := <-watcher.Error:
			log.Println("error:", err)
		}
	}
}()

err = watcher.Watch("/home/ankit/delta.txt")
if err != nil {
	log.Fatal(err)
}

// Hang so program doesn't exit
<-done

/* ... do stuff ... */
watcher.Close()

}


You may get more help here: https://github.com/fsnotify/fsnotify

I haven't been maintaining this for quite a while.

Anyway, to answer you question, If memory is correct, I believe a file is no longer watched once deleted. If you watch the folder you should get the create though.

My guess is the editor you are using for testing is doing some "magic" like renaming the file and overwriting the original or something.