Skip to content
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

Detecting rename target #15

pwaller opened this issue Sep 3, 2012 · 1 comment


None yet
2 participants
Copy link

commented Sep 3, 2012

fsnotify looks well structured, but there is one thing which makes it not very useful at the moment: it's not possible to get the rename target, nor the raw notify events. I guess that this is to have a consistent interface across operating systems.

The problem with not telling me the rename target is that gedit (a text editor) actually doesn't modify the target file directly, but creates a new file and when it is complete replaces the target by renaming over it.

At the moment fsnotify outputs these events when I hit save:

event: "/path/to/dir/.goutputstream-7U75JW": CREATE
event: "/path/to/dir/.goutputstream-7U75JW": MODIFY
event: "/path/to/dir/.goutputstream-7U75JW": MODIFY
event: "/path/to/dir/.goutputstream-7U75JW": RENAME

The end result being that I don't know what file was modified by the editor.


This comment has been minimized.

Copy link

commented Sep 10, 2012

It's not that I don't want to have this functionality. I really would, but I see no way to provide it.

FreeBSD/OSX - You need to open a file descriptor to watch it. The kevent does not specify the location of the file at all.
Look at EVFILT_NODE section of man page:

Linux - Events are received for the directory you watch, so if you are not watching the target directory, you will only get the event coming out of the directory you are watching.
Man page for reference:
Now, you can watch individual files, but as far as I know, you can't get the destination location after a rename.

Windows - I am less familiar with this one, but it appears all changes are based on the directory, not even watching individual files. So again, you need to watch the target directory.

I am hesitant to expose the underlying inotify event, because it makes the API less-consistent across operating systems and also because I'm not sure you'd gain the functionality you seek anyway.

Now, it may be possible that I have misread the documents, or there is some other way of doing this that I have not thought of. If I have missed something that will provide the rename functionality, please let me know. I'd be more than happy to rectify the situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.