fsnotify
fsnotify copied to clipboard
howeyc/fsnotify watch in window and linux problem, it‘s have some err
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
I use the example support by yours.
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.
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.
I use an edition maybe print more. could you explain the different between "echo "bb" > test.txt" and "echo "bb" >> test.txt" . thanks.
I konw "echo "bb" >> test.txt" , clean the file then write,but after clean it don't save the file.
If you're just using echo it shouldn't have the problems I mentioned about editors. Hm. I'm not sure. :frowning:
Having the same problem that it returns 2 events instead of one (using with echo)
@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!