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

Getting events only once. #117

@honeyankit

Description

@honeyankit

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

}


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions