From b326c23d633c380eaff16c50c815f867d4f37983 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 26 Feb 2018 13:35:07 +0000 Subject: [PATCH] inotify: Further fixes for hard link monitoring support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gets the G_FILE_MONITOR_WATCH_HARD_LINKS flag to the state where it doesn’t cause crashes, and essentially acts as a no-op. It will not yet actually monitor for changes made via hard links. Signed-off-by: Philip Withnall https://bugzilla.gnome.org/show_bug.cgi?id=755721 --- gio/glocalfilemonitor.c | 36 ++++++++++++++++++++++++------------ gio/inotify/inotify-helper.c | 2 -- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/gio/glocalfilemonitor.c b/gio/glocalfilemonitor.c index 7953bf0d9..c19da3ba8 100644 --- a/gio/glocalfilemonitor.c +++ b/gio/glocalfilemonitor.c @@ -229,8 +229,14 @@ g_file_monitor_source_queue_event (GFileMonitorSource *fms, event = g_slice_new (QueuedEvent); event->event_type = event_type; - if (child) + if (child != NULL && fms->dirname != NULL) event->child = g_local_file_new_from_dirname_and_basename (fms->dirname, child); + else if (child != NULL) + { + gchar *dirname = g_path_get_dirname (fms->filename); + event->child = g_local_file_new_from_dirname_and_basename (dirname, child); + g_free (dirname); + } else if (fms->dirname) event->child = _g_local_file_new (fms->dirname); else if (fms->filename) @@ -394,23 +400,29 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms, case G_FILE_MONITOR_EVENT_RENAMED: g_assert (!other && rename_to); - if (fms->flags & G_FILE_MONITOR_WATCH_MOVES) + if (fms->flags & (G_FILE_MONITOR_WATCH_MOVES | G_FILE_MONITOR_SEND_MOVED)) { GFile *other; + const gchar *dirname; + gchar *allocated_dirname = NULL; + GFileMonitorEvent event; - other = g_local_file_new_from_dirname_and_basename (fms->dirname, rename_to); - g_file_monitor_source_file_changes_done (fms, rename_to); - g_file_monitor_source_send_event (fms, G_FILE_MONITOR_EVENT_RENAMED, child, other); - g_object_unref (other); - } - else if (fms->flags & G_FILE_MONITOR_SEND_MOVED) - { - GFile *other; + event = (fms->flags & G_FILE_MONITOR_WATCH_MOVES) ? G_FILE_MONITOR_EVENT_RENAMED : G_FILE_MONITOR_EVENT_MOVED; - other = g_local_file_new_from_dirname_and_basename (fms->dirname, rename_to); + if (fms->dirname != NULL) + dirname = fms->dirname; + else + { + allocated_dirname = g_path_get_dirname (fms->filename); + dirname = allocated_dirname; + } + + other = g_local_file_new_from_dirname_and_basename (dirname, rename_to); g_file_monitor_source_file_changes_done (fms, rename_to); - g_file_monitor_source_send_event (fms, G_FILE_MONITOR_EVENT_MOVED, child, other); + g_file_monitor_source_send_event (fms, event, child, other); + g_object_unref (other); + g_free (allocated_dirname); } else { diff --git a/gio/inotify/inotify-helper.c b/gio/inotify/inotify-helper.c index d64e34d0c..0a0a84ab9 100644 --- a/gio/inotify/inotify-helper.c +++ b/gio/inotify/inotify-helper.c @@ -158,8 +158,6 @@ ih_event_callback (ik_event_t *event, gboolean interesting; GFileMonitorEvent event_flags; - g_assert (!file_event); /* XXX hardlink support */ - event_flags = ih_mask_to_EventFlags (event->mask); if (event->mask & IN_MOVE)