Subject: Re: bug#21435: 25.0.50; file-notify has problems after renames

From: Eli Zaretskii <[email-masked]>
Date: Wed, 09 Sep 2015 22:21:17 +0300

> From: Michael Albinus <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Wed, 09 Sep 2015 20:41:55 +0200
> 
> >> I couldn't test this for w32notify, but it should behave like this since
> >> Sunday.
> >
> > If you can show some simple test case, I can run it.
> 
> Well, something like this:
> 
> --8<---------------cut here---------------start------------->8---
> (progn
>   (require 'filenotify)
>   (defalias 'myhandler1 'ignore)
>   (defalias 'myhandler2 'ignore)
>   (file-notify-add-watch "/tmp" '(change) 'myhandler1)
>   (file-notify-add-watch "~/tmp" '(change) 'myhandler2)
>   (trace-function 'file-notify-handle-event)
>   (trace-function 'myhandler1)
>   (trace-function 'myhandler2))
> --8<---------------cut here---------------end--------------->8---
> 
> Then you do outside Emacs (inotify case):
> 
> --8<---------------cut here---------------start------------->8---
> # echo xxx >/tmp/xxx
> 
> ======================================================================
> 1 -> (file-notify-handle-event (file-notify (1 (create) "xxx" 0) file-notify-callback))
> | 2 -> (myhandler1 ((1) created "/tmp/xxx"))
> | 2 <- myhandler1: nil
> 1 <- file-notify-handle-event: nil
> ======================================================================
> 1 -> (file-notify-handle-event (file-notify (1 (modify) "xxx" 0) file-notify-callback))
> | 2 -> (myhandler1 ((1) changed "/tmp/xxx"))
> | 2 <- myhandler1: nil
> 1 <- file-notify-handle-event: nil

This behaves the same on w32:

======================================================================
1 -> (file-notify-handle-event (file-notify (100286560 added "xxx") file-notify-callback))
| 2 -> (myhandler1 (100286560 created "d:/tmp/xxx"))
| 2 <- myhandler1: nil
1 <- file-notify-handle-event: nil
======================================================================
1 -> (file-notify-handle-event (file-notify (100286560 modified "xxx") file-notify-callback))
| 2 -> (myhandler1 (100286560 changed "d:/tmp/xxx"))
| 2 <- myhandler1: nil
1 <- file-notify-handle-event: nil

> # mv /tmp/xxx ~/tmp/
> 
> ======================================================================
> 1 -> (file-notify-handle-event (file-notify (1 (moved-from) "xxx" 49278) file-notify-callback))
> 1 <- file-notify-handle-event: nil
> ======================================================================
> 1 -> (file-notify-handle-event (file-notify (2 (moved-to) "xxx" 49278) file-notify-callback))
> | 2 -> (myhandler1 ((1) renamed "/tmp/xxx" "/home/albinus/tmp/xxx"))
> | 2 <- myhandler1: nil
> | 2 -> (myhandler2 ((2) renamed "/tmp/xxx" "/home/albinus/tmp/xxx"))
> | 2 <- myhandler2: nil
> 1 <- file-notify-handle-event: nil
> --8<---------------cut here---------------end--------------->8---
> 
> That looks good.

This doesn't work at all on w32 (I used d:/usr/eli/data instead of
~/tmp), it reports removal and addition (and also a bogus 2nd
removal):

======================================================================
1 -> (file-notify-handle-event (file-notify (100286608 removed "xxx") file-notify-callback))
| 2 -> (myhandler2 (100286608 deleted "d:/usr/eli/data/xxx"))
| 2 <- myhandler2: nil
1 <- file-notify-handle-event: nil
======================================================================
1 -> (file-notify-handle-event (file-notify (100286608 added "xxx") file-notify-callback))
| 2 -> (myhandler2 (100286608 created "d:/usr/eli/data/xxx"))
| 2 <- myhandler2: nil
1 <- file-notify-handle-event: nil
======================================================================
1 -> (file-notify-handle-event (file-notify (100286560 removed "xxx") file-notify-callback))
| 2 -> (myhandler1 (100286560 deleted "d:/tmp/xxx"))
| 2 <- myhandler1: nil
1 <- file-notify-handle-event: nil

Let me know what I should look into or which additional information I
can give you about this.