As mentioned here: howeyc/fsnotify#104
Currently, it's not straightforward to detect a rename correctly. In most cases, one will see this:
RENAME file1
CREATE file2
Yet this doesn't guarantee that file1 and file2 are the same file (there could be a file creation in between, or file1 could be moved outside a watched folder and file2 could be moved in). To work around this, one could store the os.FileInfo for every watched file and use os.SameFile to compare it with the new file. This is a bit cumbersome though, as it requires keeping a lot of os.FileInfo structs in memory + bookkeeping them.
However, some platforms provide a way to atomically see what was the old name and what's the new name of a file. To quote @nathany:
On Linux there is a "cookie" used to tie the RENAME FROM and TO events together, but this isn't currently exposed by fsnotify. I still need to do more research across each platform.
This is a tracker issue to see if there is sufficient cross-platform support to enable this in the default API.
As mentioned here: howeyc/fsnotify#104
Currently, it's not straightforward to detect a rename correctly. In most cases, one will see this:
Yet this doesn't guarantee that
file1andfile2are the same file (there could be a file creation in between, orfile1could be moved outside a watched folder andfile2could be moved in). To work around this, one could store theos.FileInfofor every watched file and useos.SameFileto compare it with the new file. This is a bit cumbersome though, as it requires keeping a lot ofos.FileInfostructs in memory + bookkeeping them.However, some platforms provide a way to atomically see what was the old name and what's the new name of a file. To quote @nathany:
This is a tracker issue to see if there is sufficient cross-platform support to enable this in the default API.