Open JK-97 opened 4 years ago
@JK-97 What OS is that? Can you build your application with debug tag and run it again?
@JK-97 What OS is that? Can you build your application with debug tag and run it again?
my os is ubuntu 16.04 is that resulting in i use “rm -r xxx”? because it is recursive?
@JK-97 Yes and no, if you rm -rf then you're going to receive remove events for each deleted dir and file, but you shouldn't receive duplicated events on the same channel if you registered the channel only once.
The debug output I mentioned above could shed some light what's happening.
Seams to be a bug with the inotify implementation:
package main
import (
"github.com/rjeczalik/notify"
"github.com/davecgh/go-spew/spew"
)
func main() {
events := make(chan notify.EventInfo, 10)
if err := notify.Watch("/tmp/test/...", events, notify.Remove); err != nil {
panic(err.Error())
}
for event := range events {
spew.Dump(event)
}
}
action:
/tmp/test/$ mkdir a
/tmp/test/$ rmdir a
log:
2023/01/18 10:39:11.144748 [D] dispatching notify.Create on "/tmp/test/a"
2023/01/18 10:39:12.589236 [D] dispatching notify.Remove on "/tmp/test/a"
2023/01/18 10:39:12.589256 [D] dispatching notify.Remove on "/tmp/test/a"
(*notify.event)(0xc00019e0f0)(notify.Remove: "/tmp/test/a")
(*notify.event)(0xc00019e090)(notify.Remove: "/tmp/test/a")
on:
Linux cork 6.1.6-arch1-3 #1 SMP PREEMPT_DYNAMIC Mon, 16 Jan 2023 12:51:23 +0000 x86_64 GNU/Linux
Seams to only happen for folder removal though both rm -Rf
and rmdir
is affected.
OK so inotify gets a rouge 0x40000000
value, not sure what it means. It isn't listed in the man page...:
package main
import (
"github.com/davecgh/go-spew/spew"
"github.com/rjeczalik/notify"
)
func main() {
events := make(chan notify.EventInfo, 10)
if err := notify.Watch("/tmp/test/...", events, notify.Remove, notify.Rename); err != nil {
panic(err.Error())
}
for event := range events {
spew.Dump(event)
spew.Dump(event.Sys())
}
}
actions:
/tmp/test$ mkdir a
/tmp/test$ mv a b
/tmp/test$ rmdir b
log:
(*notify.event)(0xc0001ca060)(notify.Rename: "/tmp/test/a")
(*unix.InotifyEvent)(0xc0001ca060)({
Wd: (int32) 2,
Mask: (uint32) 2048,
Cookie: (uint32) 0,
Len: (uint32) 0
})
(*notify.event)(0xc0001ca000)(notify.Rename: "/tmp/test/a")
(*unix.InotifyEvent)(0xc0001ca000)({
Wd: (int32) 1,
Mask: (uint32) 1073741888,
Cookie: (uint32) 7450,
Len: (uint32) 0
})
(*notify.event)(0xc0001ca0f0)(notify.Remove: "/tmp/test/b")
(*unix.InotifyEvent)(0xc0001ca0f0)({
Wd: (int32) 1,
Mask: (uint32) 1073742336,
Cookie: (uint32) 0,
Len: (uint32) 0
})
(*notify.event)(0xc0001ca090)(notify.Remove: "/tmp/test/b")
(*unix.InotifyEvent)(0xc0001ca090)({
Wd: (int32) 2,
Mask: (uint32) 1024,
Cookie: (uint32) 0,
Len: (uint32) 0
})
name := event.Event().String()
mask := event.Sys().(*unix.InotifyEvent).Mask
if name == "notify.Rename" && (mask&unix.IN_MOVE_SELF) != 0 {
continue
} else if name == "notify.Remove" && (mask&unix.IN_DELETE_SELF) != 0 {
continue
}
Seams to give the correct effect. Not a fix though.
mycode
my watchpath is /edge/...
when i rm aa dir but the log is: INFO[0018] create/edge/mnt/aa
WARN[0020] remove/edge/mnt/aa
WARN[0020] remove/edge/mnt/aa