Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Getting events only once. #117

Open
honeyankit opened this issue Jun 27, 2017 · 1 comment
Open

Getting events only once. #117

honeyankit opened this issue Jun 27, 2017 · 1 comment

Comments

@honeyankit
Copy link

honeyankit commented Jun 27, 2017

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()

}


@howeyc
Copy link
Owner

howeyc commented Jun 28, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants