howeyc/fsnotify

Proper way to detect real rename

aktau opened this issue · 4 comments

Note: I don't necessarily need this in a cross-platform way, Linux-only would be fine. But cross-platform is always nice.

I'm making a recursive watcher for a medium-sized folder structure (~50000 files organized in a tree). I'd like to properly detect renames within the structure, so I can update some fields in a database instead of a delete/insert combo.

As of now, the only decent "solution" I've come up with is to walk the entire folder structure and save all os.FileInfo structs in a slice. Then, when a CREATE event comes (because the RENAME event doesn't mention the new name, it seems a bit useless). I check whether I already knew the file with os.SameFile, going over all saved os.FileInfo's. This sounds very heavyweight and I'd like to avoid it if at all possible.

Am I going about this the wrong way? Did I not look hard enough on Google and the mailing list (go-nuts)? (if that's the case, I apologize, I did try searching).

@aktau I haven't looked into this too much yet. 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.

Also, please see #101.

@aktau I haven't looked into this too much yet. 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.

It would be amazing if this could be done in a cross-platform fashion. I know it's not easy though. I've been watching your work (and of course of all other contributors) and I'd just like to say thanks! So I take it that my way is currently the only viable way to reliably detect renames in a folder structure with fsevents?

Also, please see #101.

In fact, I'm using the github.com/fsnotify/fsnotify package, I wasn't sure where to post though. For now, they seem to be equivalent in capabilities but a bit different in API.

Yes, they are fairly similar. I've taken the liberty of removing some (buggy) features, but little has been added. The API isn't final, but it is based on discussions with Go core team members (rsc, minux).

If you would like to open an issue to improve the Rename Op, I would be grateful:
https://github.com/fsnotify/fsnotify/issues/new

Done, thanks: fsnotify/fsnotify#26