Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Proper way to detect real rename #104

Open
aktau opened this issue Jul 8, 2014 · 4 comments
Open

Proper way to detect real rename #104

aktau opened this issue Jul 8, 2014 · 4 comments

Comments

@aktau
Copy link

aktau commented Jul 8, 2014

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).

@nathany
Copy link
Contributor

nathany commented Jul 8, 2014

@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
Copy link
Author

aktau commented Jul 8, 2014

@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.

@nathany
Copy link
Contributor

nathany commented Jul 8, 2014

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

@aktau
Copy link
Author

aktau commented Jul 8, 2014

Done, thanks: fsnotify/fsnotify#26

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants