GNOME Bugzilla – Bug 517419
gio win32 directory monitor
Last modified: 2008-03-12 19:12:04 UTC
Attached is a patch that implements a gio directory monitor. Notes: - it is based on the native ReadDirectoryChanges Win32 call. It is only a directory watcher, I saw a polling file watcher exists already - it registers itself as a GSource - it wouldn't have been necessary if the glib main loop would have used MsgWaitForMultipleObjectsEx - it's a GModule, like the fam monitor. Thinking that inotify is compiled-in on linux, I think the same can be said for windows about ReadDirectoryWatcher - it may have bugs / may need code cleanup? it's here to be tested.. Regards,
Created attachment 105572 [details] [review] win32 directory monitor Initial implementation as GModule
> it registers itself as a GSource - it wouldn't have been necessary > if the glib main loop would have used MsgWaitForMultipleObjectsEx If you can come up with a simple enhancement to the glib main loop implementation on Win32 that preserves backward compatibility, while making your directory monitor simpler, I wouldn't object at all. I haven't yet looked in detail at the patch, but I noticed it uses WideCharToMultiByte() to convert a wide-char filename to system codepage, then passes that to g_file_new_for_path(). In general all file names passed to and returned from GLib APIs are in UTF-8 on Windows, so you should use g_utf16_to_utf8() instead. (If g_file_new_for_path() in fact *does* currently expect a pathname in system codepage, that is then a bug.)
Created attachment 105588 [details] [review] now using g_utf16_to_utf8 () Sorry, I left that unintentionally - I use g_utf15_to_utf8 () now (and I fixed a leak too) in the next patch. For the main loop I wrote on #517484. On my machine it does not have side effects but YMMV.
> it registers itself as a GSource - it wouldn't have been necessary if > the glib main loop would have used MsgWaitForMultipleObjectsEx That change has now been committed, so could you simplify the code correspondingly? (Or did I misunderstand something...?) Please make it into a static archive that is always linked into libgio, like libinotify on Linux. Also, the patch contains two copies of each diff to gio/win32...
Created attachment 105987 [details] [review] implemented without gsource/events Ok, here's the source code with the implementation without CreateEvent () => g_source_attach () Also, it's linked directly, just like the inotify monitor. One quirk, though: it still needs a gmain.c modification I overlooked (see bug #517484) If it's not possible to make it, I can still submit the old version directly linked.
Created attachment 106059 [details] [review] implemented without gsource/events (+finalize mess cleanup) Cleaned up some finalize () mess from the previous patch
Patch committed to trunk, thanks! (Now I only need to find some suitable small test application to test the new, and gio functionality in general, on Windows...) Feel free to reopen this bug if/when you have further changes. Once we are sure this stuff works fine it probably can be committed to the stable glib-2-16 branch, too, as it doesn't introduce any new API as such.