-
-
Notifications
You must be signed in to change notification settings - Fork 886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved "rename" support #26
Comments
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as spam.
This comment was marked as spam.
I think watchdog (https://github.com/gorakhargosh/watchdog) has figured out a cross-platform API, by the way. |
@jmhodges Do you have any more details on "Weird Things" vim does? Is this when saving or is there a rename file function people are using in Vim? |
ref: rjeczalik/notify#78 |
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as outdated.
This comment was marked as outdated.
Do you think keeping a list of |
Having done some experimentation on Windows, the |
This comment was marked as spam.
This comment was marked as spam.
Once #114 is implemented, I think you can do this using
|
fanotify isn't needed. It's already implemented in inotify. See: #628. |
Interesting. @arp242 how do you know when to give up waiting for a matching cookie? E.g. if you move a file to a different file system, you will never get a matching cookie and should issue a delete event. Do you have to the wait until 10 other operations on the file system have been made? You could potentially be waiting days before that happens. Is there or should there also be some sort of timeout to avoid waiting too long? Since I think you probably need a timeout anyway, would it not be sufficient to solely rely on the timeout to limit the cache size rather than limiting to ten entries? Anyway, what I was referring to with |
It doesn't wait for anything; you either get a IN_MOVED_TO event or you don't. It just keeps a small cache to survive to survive event reordering.
No, because the file is not deleted. |
So what do you do if you never get the |
IN_MOVED_FROM always triggers Rename, and IN_MOVED_TO (which may or may not arrive) triggers Create. |
I see. So basically the consumer is responsible for setting up the timer to decide whether or not to keep waiting for |
That depends what you want I guess; in a lot of use cases just wait for a Create with RenamedFrom is fine, and/or treating Rename as Delete. All of this has worked like this for 10 years or so; we can't easily change it. Never mind cross-platform considerations. I don't really get what you're asking in any case; if you have a concrete problem or use case then ask that. |
You've already answered all my questions. Thanks! As for my usecase, I want to handle renames to the extent possible - i.e. handling them as renames when I receive both events and otherwise handle them as create/delete when receiving only one event (depending on whether the file was moved to/from the watched location). To do so, I believe I either need to use a timer or use |
FAN_RENAME is only triggered inside watched directories, so that behaviour isn't any different. And even if it would be, a fanotify backend here should not send different events; the entire point of this library is to provide a cross-platform experience, so you can develop something on Linux and be reasonably confident it works on Windows. And stuff like that. If one backend starts sending events that aren't supported by other backends then that breaks. |
Yes, it's only triggered inside watched directories, but the part that is different is that I believe it sends the details in a single event instead of splitting it across two events. Fair point about needing the same functionality on Mac and Windows though. |
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
file1
andfile2
are the same file (there could be a file creation in between, orfile1
could be moved outside a watched folder andfile2
could be moved in). To work around this, one could store theos.FileInfo
for every watched file and useos.SameFile
to compare it with the new file. This is a bit cumbersome though, as it requires keeping a lot ofos.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:
This is a tracker issue to see if there is sufficient cross-platform support to enable this in the default API.
The text was updated successfully, but these errors were encountered: