SpartanJ / efsw

efsw is a C++ cross-platform file system watcher and notifier.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't watch for file attribute changes

SpartanJ opened this issue · comments

Original report by James Beaumont-Field (Bitbucket: [T B](https://bitbucket.org/T B), ).


It would be great to also be able to (optionally) watch for changes to file attributes. On windows the change looks to be trivial

#!c++

	WatcherStructWin32 * watch = CreateWatch( String::fromUtf8( dir ).toWideString().c_str(), recursive,		FILE_NOTIFY_CHANGE_CREATION |
																			FILE_NOTIFY_CHANGE_LAST_WRITE |
																			FILE_NOTIFY_CHANGE_FILE_NAME |
																			FILE_NOTIFY_CHANGE_DIR_NAME |
                                                                            FILE_NOTIFY_CHANGE_ATTRIBUTES |
																			FILE_NOTIFY_CHANGE_SIZE

in FileWatcherWin32.cpp (I guess you'd want to add the FILE_NOTIFY_CHANGE_ATTRIBUTES based on some input param). Haven't really investigated for POSIX.

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Hi T B!

Sorry for the huge delay!

I think this should be trivial in all OSes. The problem is that the behavior could be a little different in each implementation and could cause problems for multi-platform apps using that feature. I should take a look at that. Can you please give me an example for a use case escenario of this feature? What do you need to know specifically?

Thanks,

Regards

Original comment by Dovod Dovodov (Bitbucket: ddovod, GitHub: ddovod).


Hi Martin. Thank you very much for you work, this library is awesome!
My use-case is as following.

I need to watch for source file changes to trigger code recompilation if smth was changed. I'm not interested in attributes, owner and other changes not related to the file content. I want to filter out all non-content file events to not trigger expensive compiler call.
So basically what I'm looking for is to have the ability to receive platform event type to filter it myself for each platform.

Example: my code editor on macOS triggers kFSEventStreamEventFlagItemModified when file is changed, and it is fine. But when I just open some file in Xcode, I get kFSEventStreamEventFlagItemXattrMod, and ofc I don't want to recompile the file if only some attributes was changed. Right now as a quick fix I've just removed kFSEventStreamEventFlagItemXattrMod from the efswFSEventsModified mask, and it works good for me.

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Hi Dovod! Fist of all, thanks for your kind words.
What you're describing is definitely a bug. The default behavior should be as you described, attribute changes should be ignored. I don't know how this stayed so much time without being noticed, but i'll change it. Apart from that, i'm reading the code after many years of not touching the macOS implementation and I've doubts on why it was implemented in that way. FSEvents documenation is horrendous, some of this flags i don't remember exactly when they are triggered, but for the moment i'll disable kFSEventStreamEventFlagItemXattrMod and probably kFSEventStreamEventFlagItemChangeOwner also. I'll take a look in more depth before pushing any changes.

Thank you for taking the time to describing this bug! I'll have to reconsider implementing what the author of this issue requested, but i still don't see many use case scenarios for tracking attribute changes.

Regards

Original comment by Dovod Dovodov (Bitbucket: ddovod, GitHub: ddovod).


Hey Martin, thank you for your response and support!

So if the original intention was not to pass file property changes as modification events, this sounds totally reasonable. Probably it's worth to create a separate Action for such event types, just in case. But I also don't see any useful application to this.