inotify: Further fixes for hard link monitoring support

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 <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=755721
This commit is contained in:
Philip Withnall 2018-02-26 13:35:07 +00:00
parent cc5cd5e8ea
commit 3e4e005c96
2 changed files with 24 additions and 14 deletions

View File

@ -229,8 +229,14 @@ g_file_monitor_source_queue_event (GFileMonitorSource *fms,
event = g_slice_new (QueuedEvent); event = g_slice_new (QueuedEvent);
event->event_type = event_type; 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); 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) else if (fms->dirname)
event->child = _g_local_file_new (fms->dirname); event->child = _g_local_file_new (fms->dirname);
else if (fms->filename) else if (fms->filename)
@ -394,23 +400,29 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
case G_FILE_MONITOR_EVENT_RENAMED: case G_FILE_MONITOR_EVENT_RENAMED:
g_assert (!other && rename_to); 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; GFile *other;
const gchar *dirname;
gchar *allocated_dirname = NULL;
GFileMonitorEvent event;
other = g_local_file_new_from_dirname_and_basename (fms->dirname, rename_to); event = (fms->flags & G_FILE_MONITOR_WATCH_MOVES) ? G_FILE_MONITOR_EVENT_RENAMED : G_FILE_MONITOR_EVENT_MOVED;
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;
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_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_object_unref (other);
g_free (allocated_dirname);
} }
else else
{ {

View File

@ -158,8 +158,6 @@ ih_event_callback (ik_event_t *event,
gboolean interesting; gboolean interesting;
GFileMonitorEvent event_flags; GFileMonitorEvent event_flags;
g_assert (!file_event); /* XXX hardlink support */
event_flags = ih_mask_to_EventFlags (event->mask); event_flags = ih_mask_to_EventFlags (event->mask);
if (event->mask & IN_MOVE) if (event->mask & IN_MOVE)