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

howeyc/fsnotify watch in window and linux problem, it‘s have some err #113

Open
woqunokia opened this issue Nov 24, 2015 · 8 comments
Open

Comments

@woqunokia
Copy link

OS:window7
folder
create:
"D:\test\新建文件夹": CREATE
rename
2015/11/24 15:02:39 event: "D:\test\新建文件夹": RENAME
2015/11/24 15:02:39 event: "D:\test\test": RENAME

delete
2015/11/24 15:03:12 event: "D:\test\test": DELETE
MODIFY
2015/11/24 15:04:37 event: "D:\test\ww": MODIFY

file
create
2015/11/24 15:05:33 event: "D:\test\新建文本文档.txt": CREATE
rename
2015/11/24 15:05:52 event: "D:\test\新建文本文档.txt": RENAME
2015/11/24 15:05:52 event: "D:\test\test.txt": RENAME
2015/11/24 15:05:52 event: "D:\test\test.txt": MODIFY
why print MODIFY?
MODIFY
2015/11/24 15:06:14 event: "D:\test\test.txt": MODIFY
2015/11/24 15:06:14 event: "D:\test\test.txt": MODIFY
2015/11/24 15:06:14 event: "D:\test\test.txt": MODIFY
why this line run 3times?
delete
2015/11/24 15:08:15 event: "D:\test\test.txt": DELETE

OS:centos
folder
create:
2015/11/24 15:11:52 event: "/root/桌面/test/untitled folder": CREATE
rename
2015/11/24 15:12:23 event: "/root/桌面/test/untitled folder": RENAME
2015/11/24 15:12:23 event: "/root/桌面/test/test": CREATE
delete
2015/11/24 15:17:18 event: "/root/桌面/test/test": RENAME
MODIFY
nothing

file
create
2015/11/24 15:20:10 event: "/root/桌面/test/new file": CREATE
rename
2015/11/24 15:20:31 event: "/root/桌面/test/new file": RENAME
2015/11/24 15:20:31 event: "/root/桌面/test/test": CREATE
MODIFY
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": CREATE
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": MODIFY|ATTRIB
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": MODIFY|ATTRIB
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": MODIFY|ATTRIB
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": MODIFY
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": MODIFY
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": MODIFY
2015/11/24 15:20:58 event: "/root/桌面/test/test": RENAME //rename
2015/11/24 15:20:58 event: "/root/桌面/test/.gedit-save-D5SP8X": RENAME
2015/11/24 15:20:58 event: "/root/桌面/test/test": CREATE
2015/11/24 15:20:58 event: "/root/桌面/test/test~": DELETE
About file test only 2 lines but it's rename and create
delete
2015/11/24 15:29:53 event: "/root/桌面/test/test": RENAME

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)
            if ev.IsModify() {
                log.Println("xxxxxxxxxxxx")
            }
        case err := <-watcher.Error:
            log.Println("error:", err)
        }
    }
}()

err = watcher.Watch("/root/桌面/test")
//err = watcher.Watch("/hard/psq")
if err != nil {
    log.Fatal(err)
}

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

//select{}

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

}

if i watch a file ,
package main

import (
"log"
//"fmt"
"github.com/howeyc/fsnotify"
)

func test(){
log.Println("test")
}

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)
            if ev.IsModify() {
                log.Println("xxxxxxxxxxxx")
            }
            //test()
        case err := <-watcher.Error:
            log.Println("error:", err)
        }
    }
}()

err = watcher.Watch("/root/桌面/test/test.txt")
//err = watcher.Watch("/hard/psq")
if err != nil {
    log.Fatal(err)
}

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

//select{}

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

}
when i MODIFY the file test.txt it's only print in the first time . in windows it's print 3times

@woqunokia
Copy link
Author

I use the example support by yours.

@nathany
Copy link
Contributor

nathany commented Nov 24, 2015

You can try using https://github.com/go-fsnotify/fsnotify which has some bugfixes that haven't been incorporated into howeyc/fsnotify.

Though it may not fix things like multiple modify events, particularly if you are triggering these changes with a text editor. Editors are notorious for causing issues like that https://github.com/go-fsnotify/fsnotify/issues/17.

@woqunokia
Copy link
Author

Thank you,
I tried. but when modify by "echo "bb" >> test.txt" (it's append in the end of file ) like this, it's print once, but if i use "bb" >> test.txt" ,it's print 2 times.(in window and linux are same).
if open the file with edition , it's print 3 or 2 times.

@woqunokia
Copy link
Author

I use an edition maybe print more. could you explain the different between "echo "bb" > test.txt" and
"echo "bb" >> test.txt" .
thanks.

@woqunokia
Copy link
Author

I konw "echo "bb" >> test.txt" , clean the file then write,but after clean it don't save the file.

@nathany
Copy link
Contributor

nathany commented Nov 26, 2015

If you're just using echo it shouldn't have the problems I mentioned about editors. Hm. I'm not sure. 😦

@pkutishch
Copy link

Having the same problem that it returns 2 events instead of one (using with echo)

@nathany
Copy link
Contributor

nathany commented Nov 8, 2016

@pkutishch Would you mind trying against the latest version by running the following in terminal/console:

go get -u github.com/fsnotify/fsnotify

and changing import paths to:

import "github.com/fsnotify/fsnotify"

If echo is still a problem, please open a new issue there.
https://github.com/fsnotify/fsnotify/issues/new

Thanks!

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

3 participants