rjeczalik / notify

File system event notification library on steroids.
MIT License
896 stars 127 forks source link

Help request #101

Closed iowelinux closed 8 years ago

iowelinux commented 8 years ago

Hi,

Actually this is not an issue however I believe your answer would be really helpful for lots of developers. Here is a simple code I try to run.

func main() {

    log.Println("fswatch started")
    c := make(chan notify.EventInfo, 1000)

    if err := notify.Watch(".", c, notify.All); err != nil {
        log.Fatal(err)
    }
    defer notify.Stop(c)

    for {
        ei := <-c
        log.Println(ei.Path(), ei.Event().String())
    }
}

Nothing is logged. Do I do something wrong?

rjeczalik commented 8 years ago

Nothing is logged.

What should be logged? Could you go run -tags debug main.go, do whatever file operations you're doing and then paste the output here?

iowelinux commented 8 years ago

What should be logged?

As you can see in the code path and event type should be printed using log.Println

Seems like it was some kind of mistake at my side because the same code works now. Sorry for that. I can detect Remove, Create, Rename events but can't get access events at all.

For instance running the following commands on Linux doesn't output anything:

cat test

nothing.

#!/usr/bin/perl

open FH, "test";
while (<FH>) {
  print $_;
}
close FH;

nothing.

I believe InAccess and InOpen events should be detected in this case. Shouldn't it? All test were done on Linux 3.10.0 x86_64 kernel

rjeczalik commented 8 years ago

https://godoc.org/github.com/rjeczalik/notify#pkg-constants

notify.All is defined as:

const (
    Create = osSpecificCreate
    Remove = osSpecificRemove
    Write  = osSpecificWrite
    Rename = osSpecificRename

    // All is handful alias for all platform-independent event values.
    All = Create | Remove | Write | Rename
)

If you want linux-specific events like notify.InAccess, you need to pass it additionally.