dzl-recursive-file-monitor.c 21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* dzl-recursive-file-monitor.c
 *
 * Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define G_LOG_DOMAIN "dzl-recursive-file-monitor"

21 22
#include "config.h"

23 24 25
#include <limits.h>
#include <stdlib.h>

26 27 28
#include "files/dzl-recursive-file-monitor.h"
#include "util/dzl-macros.h"

29 30
#define MONITOR_FLAGS 0

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/**
 * SECTION:dzl-recursive-file-monitor
 * @title: DzlRecursiveFileMonitor
 * @short_description: a recursive directory monitor
 *
 * This works by creating a #GFileMonitor for each directory underneath a root
 * directory (and recursively beyond that).
 *
 * This is only designed for use on Linux, where we are using a single inotify
 * FD. You can still hit the max watch limit, but it is much higher than the FD
 * limit.
 *
 * Since: 3.28
 */

46 47
struct _DzlRecursiveFileMonitor
{
48
  GObject                 parent_instance;
49

50 51
  GFile                  *root;
  GCancellable           *cancellable;
52

53 54
  GHashTable             *monitors_by_file;
  GHashTable             *files_by_monitor;
55

56 57 58
  DzlRecursiveIgnoreFunc  ignore_func;
  gpointer                ignore_func_data;
  GDestroyNotify          ignore_func_data_destroy;
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
};

enum {
  PROP_0,
  PROP_ROOT,
  N_PROPS
};

enum {
  CHANGED,
  N_SIGNALS
};

G_DEFINE_TYPE (DzlRecursiveFileMonitor, dzl_recursive_file_monitor, G_TYPE_OBJECT)

static GParamSpec *properties [N_PROPS];
static guint signals [N_SIGNALS];

77 78 79 80
static void
dzl_recursive_file_monitor_track (DzlRecursiveFileMonitor *self,
                                  GFile                   *dir,
                                  GFileMonitor            *monitor);
81

82 83 84 85 86 87
static void
dzl_recursive_file_monitor_unwatch (DzlRecursiveFileMonitor *self,
                                    GFile                   *file)
{
  GFileMonitor *monitor;

88
  dzl_assert_is_main_thread ();
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  g_assert (DZL_IS_RECURSIVE_FILE_MONITOR (self));
  g_assert (G_IS_FILE (file));

  monitor = g_hash_table_lookup (self->monitors_by_file, file);

  if (monitor != NULL)
    {
      g_object_ref (monitor);
      g_file_monitor_cancel (monitor);
      g_hash_table_remove (self->monitors_by_file, file);
      g_hash_table_remove (self->files_by_monitor, monitor);
      g_object_unref (monitor);
    }
}

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
static void
dzl_recursive_file_monitor_collect_recursive (GPtrArray    *dirs,
                                              GFile        *parent,
                                              GCancellable *cancellable)
{
  g_autoptr(GFileEnumerator) enumerator = NULL;
  g_autoptr(GError) error = NULL;

  g_assert (dirs != NULL);
  g_assert (G_IS_FILE (parent));
  g_assert (G_IS_CANCELLABLE (cancellable));

  enumerator = g_file_enumerate_children (parent,
                                          G_FILE_ATTRIBUTE_STANDARD_NAME","
                                          G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                          G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                          cancellable, &error);

  if (error != NULL)
    {
      g_warning ("Failed to iterate children: %s", error->message);
      g_clear_error (&error);
    }

  if (enumerator != NULL)
    {
      gpointer infoptr;

      while (NULL != (infoptr = g_file_enumerator_next_file (enumerator, cancellable, NULL)))
        {
          g_autoptr(GFileInfo) info = infoptr;

          if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
            {
              const gchar *name = g_file_info_get_name (info);
139 140 141 142 143 144 145 146 147 148 149 150
              g_autoptr(GFile) child = g_file_get_child (parent, name);

              /*
               * We add the child, and then recurse into the child immediately
               * so that we can keep the invariant that all descendants
               * immediately follow their ancestor. This allows us to simplify
               * our ignored-directory checks when we get back to the main
               * thread.
               */

              g_ptr_array_add (dirs, g_object_ref (child));
              dzl_recursive_file_monitor_collect_recursive (dirs, child, cancellable);
151 152 153 154 155 156 157 158
            }
        }

      g_file_enumerator_close (enumerator, cancellable, NULL);
      g_clear_object (&enumerator);
    }
}

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
static GFile *
resolve_file (GFile *file)
{
  g_autofree gchar *orig_path = NULL;
  g_autoptr(GFile) new_file = NULL;
  char *real_path;

  g_assert (G_IS_FILE (file));

  /*
   * The goal here is to work our way up to the root and resolve any
   * symlinks in the path. If the file is not native, we don't care
   * about symlinks.
   */
  if (!g_file_is_native (file))
    return g_object_ref (file);

  orig_path = g_file_get_path (file);
177
#ifdef G_OS_UNIX
178
  real_path = realpath (orig_path, NULL);
179 180 181
#else
  real_path = _fullpath (orig_path, NULL, _MAX_PATH);
#endif
182 183 184 185 186 187 188 189 190 191 192

  /* unlikely, but PATH_MAX exceeded */
  if (real_path == NULL)
    return g_object_ref (file);

  new_file = g_file_new_for_path (real_path);
  free (real_path);

  return g_steal_pointer (&new_file);
}

193 194 195 196 197 198 199
static void
dzl_recursive_file_monitor_collect_worker (GTask        *task,
                                           gpointer      source_object,
                                           gpointer      task_data,
                                           GCancellable *cancellable)
{
  g_autoptr(GPtrArray) dirs = NULL;
200
  g_autoptr(GFile) resolved = NULL;
201 202 203 204 205
  GFile *root = task_data;

  g_assert (G_IS_TASK (task));
  g_assert (G_IS_FILE (root));

206 207 208 209 210 211 212 213
  /* The first thing we want to do is resolve any symlinks out of
   * the path so that we are consistently working with the real
   * system path. This improves interaction with other APIs that
   * might not have given the callee back the symlink'd path and
   * instead the real path.
   */
  resolved = resolve_file (root);

214
  dirs = g_ptr_array_new_with_free_func (g_object_unref);
215 216
  g_ptr_array_add (dirs, g_object_ref (resolved));
  dzl_recursive_file_monitor_collect_recursive (dirs, resolved, cancellable);
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

  g_task_return_pointer (task,
                         g_steal_pointer (&dirs),
                         (GDestroyNotify)g_ptr_array_unref);
}

static void
dzl_recursive_file_monitor_collect (DzlRecursiveFileMonitor *self,
                                    GFile                   *root,
                                    GCancellable            *cancellable,
                                    GAsyncReadyCallback      callback,
                                    gpointer                 user_data)
{
  g_autoptr(GTask) task = NULL;

  g_assert (DZL_IS_RECURSIVE_FILE_MONITOR (self));
  g_assert (G_IS_FILE (root));
  g_assert (G_IS_CANCELLABLE (cancellable));

  task = g_task_new (self, cancellable, callback, user_data);
  g_task_set_source_tag (task, dzl_recursive_file_monitor_collect);
  g_task_set_priority (task, G_PRIORITY_LOW);
  g_task_set_task_data (task, g_object_ref (root), g_object_unref);
  g_task_run_in_thread (task, dzl_recursive_file_monitor_collect_worker);
}

static GPtrArray *
dzl_recursive_file_monitor_collect_finish (DzlRecursiveFileMonitor  *self,
                                           GAsyncResult             *result,
                                           GError                  **error)
{
  g_assert (DZL_IS_RECURSIVE_FILE_MONITOR (self));
  g_assert (G_IS_TASK (result));
  g_assert (g_task_is_valid (G_TASK (result), self));

  return g_task_propagate_pointer (G_TASK (result), error);
}

static gboolean
dzl_recursive_file_monitor_ignored (DzlRecursiveFileMonitor *self,
                                    GFile                   *file)
{
  dzl_assert_is_main_thread ();
  g_assert (DZL_IS_RECURSIVE_FILE_MONITOR (self));
  g_assert (G_IS_FILE (file));

  if (self->ignore_func != NULL)
    return self->ignore_func (file, self->ignore_func_data);

  return FALSE;
}

269 270 271 272 273 274 275
static void
dzl_recursive_file_monitor_changed (DzlRecursiveFileMonitor *self,
                                    GFile                   *file,
                                    GFile                   *other_file,
                                    GFileMonitorEvent        event,
                                    GFileMonitor            *monitor)
{
276
  dzl_assert_is_main_thread ();
277 278 279 280 281
  g_assert (DZL_IS_RECURSIVE_FILE_MONITOR (self));
  g_assert (G_IS_FILE (file));
  g_assert (!other_file || G_IS_FILE (file));
  g_assert (G_IS_FILE_MONITOR (monitor));

282 283 284
  if (g_cancellable_is_cancelled (self->cancellable))
    return;

285
  if (dzl_recursive_file_monitor_ignored (self, file))
286
    return;
287

288 289 290 291 292 293 294
  if (event == G_FILE_MONITOR_EVENT_DELETED)
    {
      if (g_hash_table_contains (self->monitors_by_file, file))
        dzl_recursive_file_monitor_unwatch (self, file);
    }
  else if (event == G_FILE_MONITOR_EVENT_CREATED)
    {
295
      if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_DIRECTORY)
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
        {
          g_autoptr(GPtrArray) dirs = NULL;

          dirs = g_ptr_array_new_with_free_func (g_object_unref);
          g_ptr_array_add (dirs, g_object_ref (file));

          dzl_recursive_file_monitor_collect_recursive (dirs, file, self->cancellable);

          for (guint i = 0; i < dirs->len; i++)
            {
              g_autoptr(GFileMonitor) dir_monitor = NULL;
              GFile *dir = g_ptr_array_index (dirs, i);

              if (!!(dir_monitor = g_file_monitor_directory (dir, MONITOR_FLAGS, self->cancellable, NULL)))
                dzl_recursive_file_monitor_track (self, dir, dir_monitor);
            }
        }
313 314 315 316 317 318
    }

  g_signal_emit (self, signals [CHANGED], 0, file, other_file, event);
}


319 320 321 322 323 324
static void
dzl_recursive_file_monitor_track (DzlRecursiveFileMonitor *self,
                                  GFile                   *dir,
                                  GFileMonitor            *monitor)
{
  dzl_assert_is_main_thread ();
325
  g_assert (DZL_IS_RECURSIVE_FILE_MONITOR (self));
326 327
  g_assert (G_IS_FILE (dir));
  g_assert (G_IS_FILE_MONITOR (monitor));
328

329 330 331
  g_hash_table_insert (self->monitors_by_file,
                       g_object_ref (dir),
                       g_object_ref (monitor));
332

333 334 335
  g_hash_table_insert (self->files_by_monitor,
                       g_object_ref (monitor),
                       g_object_ref (dir));
336 337 338 339 340 341 342 343 344

  g_signal_connect_object (monitor,
                           "changed",
                           G_CALLBACK (dzl_recursive_file_monitor_changed),
                           self,
                           G_CONNECT_SWAPPED);
}

static void
345 346 347
dzl_recursive_file_monitor_start_cb (GObject      *object,
                                     GAsyncResult *result,
                                     gpointer      user_data)
348
{
349 350
  DzlRecursiveFileMonitor *self = (DzlRecursiveFileMonitor *)object;
  g_autoptr(GPtrArray) dirs = NULL;
351
  g_autoptr(GError) error = NULL;
352
  g_autoptr(GTask) task = user_data;
353

354
  dzl_assert_is_main_thread ();
355
  g_assert (DZL_IS_RECURSIVE_FILE_MONITOR (self));
356 357
  g_assert (G_IS_ASYNC_RESULT (result));
  g_assert (G_IS_TASK (task));
358

359
  dirs = dzl_recursive_file_monitor_collect_finish (self, result, &error);
360

361
  if (dirs == NULL)
362
    {
363 364 365
      g_task_return_error (task, g_steal_pointer (&error));
      return;
    }
366

367 368 369 370
  for (guint i = 0; i < dirs->len; i++)
    {
      GFile *dir = g_ptr_array_index (dirs, i);
      g_autoptr(GFileMonitor) monitor = NULL;
371

372
      g_assert (G_IS_FILE (dir));
373

374
      if (dzl_recursive_file_monitor_ignored (self, dir))
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
        {
          /*
           * Skip ahead to the next directory that does not have this directory
           * as a prefix. We can do this because we know the descendants are
           * guaranteed to immediately follow this directory.
           */

          for (guint j = i + 1; j < dirs->len; j++, i++)
            {
              GFile *next = g_ptr_array_index (dirs, j);

              if (!g_file_has_prefix (next, dir))
                break;
            }

          continue;
        }
392

393
      monitor = g_file_monitor_directory (dir, MONITOR_FLAGS, self->cancellable, &error);
394

395 396 397 398 399 400
      if (monitor == NULL)
        {
          g_warning ("Failed to monitor directory: %s", error->message);
          g_clear_error (&error);
          continue;
        }
401

402 403
      dzl_recursive_file_monitor_track (self, dir, monitor);
    }
404

405
  g_task_return_boolean (task, TRUE);
406 407
}

408 409 410 411 412
void
dzl_recursive_file_monitor_start_async (DzlRecursiveFileMonitor *self,
                                        GCancellable            *cancellable,
                                        GAsyncReadyCallback      callback,
                                        gpointer                 user_data)
413 414 415
{
  g_autoptr(GTask) task = NULL;

416 417
  g_return_if_fail (DZL_IS_RECURSIVE_FILE_MONITOR (self));
  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
418

419 420
  task = g_task_new (self, cancellable, callback, user_data);
  g_task_set_source_tag (task, dzl_recursive_file_monitor_start_async);
421
  g_task_set_return_on_cancel (task, TRUE);
422 423 424 425 426 427 428 429 430 431 432
  g_task_set_task_data (task, g_object_ref (self->root), g_object_unref);
  g_task_set_priority (task, G_PRIORITY_LOW);

  if (self->root == NULL)
    {
      g_task_return_new_error (task,
                               G_IO_ERROR,
                               G_IO_ERROR_INVAL,
                               "Cannot start file monitor, no root directory set");
      return;
    }
433

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
  dzl_recursive_file_monitor_collect (self,
                                      self->root,
                                      self->cancellable,
                                      dzl_recursive_file_monitor_start_cb,
                                      g_steal_pointer (&task));
}

gboolean
dzl_recursive_file_monitor_start_finish (DzlRecursiveFileMonitor  *self,
                                         GAsyncResult             *result,
                                         GError                  **error)
{
  g_return_val_if_fail (DZL_IS_RECURSIVE_FILE_MONITOR (self), FALSE);
  g_return_val_if_fail (G_IS_TASK (result), FALSE);
  g_return_val_if_fail (g_task_is_valid (G_TASK (result), self), FALSE);

  return g_task_propagate_boolean (G_TASK (result), error);
451 452 453 454 455 456 457 458 459 460
}

static void
dzl_recursive_file_monitor_constructed (GObject *object)
{
  DzlRecursiveFileMonitor *self = (DzlRecursiveFileMonitor *)object;

  G_OBJECT_CLASS (dzl_recursive_file_monitor_parent_class)->constructed (object);

  if (self->root == NULL)
461
    g_warning ("%s created without a root directory", G_OBJECT_TYPE_NAME (self));
462 463
}

464 465 466 467 468 469
static void
dzl_recursive_file_monitor_dispose (GObject *object)
{
  DzlRecursiveFileMonitor *self = (DzlRecursiveFileMonitor *)object;

  g_cancellable_cancel (self->cancellable);
470
  dzl_recursive_file_monitor_set_ignore_func (self, NULL, NULL, NULL);
471

472 473 474
  g_hash_table_remove_all (self->files_by_monitor);
  g_hash_table_remove_all (self->monitors_by_file);

475 476 477 478 479 480 481 482 483 484 485
  G_OBJECT_CLASS (dzl_recursive_file_monitor_parent_class)->dispose (object);
}

static void
dzl_recursive_file_monitor_finalize (GObject *object)
{
  DzlRecursiveFileMonitor *self = (DzlRecursiveFileMonitor *)object;

  g_clear_object (&self->root);
  g_clear_object (&self->cancellable);

486 487
  g_clear_pointer (&self->files_by_monitor, g_hash_table_unref);
  g_clear_pointer (&self->monitors_by_file, g_hash_table_unref);
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546

  G_OBJECT_CLASS (dzl_recursive_file_monitor_parent_class)->finalize (object);
}

static void
dzl_recursive_file_monitor_get_property (GObject    *object,
                                         guint       prop_id,
                                         GValue     *value,
                                         GParamSpec *pspec)
{
  DzlRecursiveFileMonitor *self = DZL_RECURSIVE_FILE_MONITOR (object);

  switch (prop_id)
    {
    case PROP_ROOT:
      g_value_set_object (value, dzl_recursive_file_monitor_get_root (self));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
dzl_recursive_file_monitor_set_property (GObject      *object,
                                         guint         prop_id,
                                         const GValue *value,
                                         GParamSpec   *pspec)
{
  DzlRecursiveFileMonitor *self = DZL_RECURSIVE_FILE_MONITOR (object);

  switch (prop_id)
    {
    case PROP_ROOT:
      self->root = g_value_dup_object (value);
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}

static void
dzl_recursive_file_monitor_class_init (DzlRecursiveFileMonitorClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->constructed = dzl_recursive_file_monitor_constructed;
  object_class->dispose = dzl_recursive_file_monitor_dispose;
  object_class->finalize = dzl_recursive_file_monitor_finalize;
  object_class->get_property = dzl_recursive_file_monitor_get_property;
  object_class->set_property = dzl_recursive_file_monitor_set_property;

  properties [PROP_ROOT] =
    g_param_spec_object ("root",
                         "Root",
                         "The root directory to monitor",
                         G_TYPE_FILE,
                         (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
547

548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
  g_object_class_install_properties (object_class, N_PROPS, properties);

  /**
   * DzlRecursiveFileMonitor::changed:
   * @self: a #DzlRecursiveFileMonitor
   * @file: a #GFile
   * @other_file: (nullable): a #GFile for the other file when applicable
   * @event: the #GFileMonitorEvent event
   *
   * This event is similar to #GFileMonitor::changed but can be fired from
   * any of the monitored directories in the recursive mount.
   *
   * Since: 3.28
   */
  signals [CHANGED] =
    g_signal_new ("changed",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_LAST,
                  0, NULL, NULL, NULL,
                  G_TYPE_NONE, 3, G_TYPE_FILE, G_TYPE_FILE, G_TYPE_FILE_MONITOR_EVENT);
}

static void
dzl_recursive_file_monitor_init (DzlRecursiveFileMonitor *self)
{
  self->cancellable = g_cancellable_new ();
  self->files_by_monitor = g_hash_table_new_full (NULL, NULL, g_object_unref, g_object_unref);
  self->monitors_by_file = g_hash_table_new_full (g_file_hash,
                                                  (GEqualFunc) g_file_equal,
                                                  g_object_unref,
                                                  g_object_unref);
}

DzlRecursiveFileMonitor *
dzl_recursive_file_monitor_new (GFile *file)
{
  g_return_val_if_fail (G_IS_FILE (file), NULL);

  return g_object_new (DZL_TYPE_RECURSIVE_FILE_MONITOR,
                       "root", file,
                       NULL);
}

/**
 * dzl_recursive_file_monitor_cancel:
 * @self: a #DzlRecursiveFileMonitor
 *
 * Cancels the recursive file monitor.
 *
 * Since: 3.28
 */
void
dzl_recursive_file_monitor_cancel (DzlRecursiveFileMonitor *self)
{
  g_return_if_fail (DZL_IS_RECURSIVE_FILE_MONITOR (self));

  g_object_run_dispose (G_OBJECT (self));
}

/**
 * dzl_recursive_file_monitor_get_root:
 * @self: a #DzlRecursiveFileMonitor
 *
 * Gets the root directory used forthe file monitor.
 *
 * Returns: (transfer none): a #GFile
 *
 * Since: 3.28
 */
GFile *
dzl_recursive_file_monitor_get_root (DzlRecursiveFileMonitor *self)
{
  g_return_val_if_fail (DZL_IS_RECURSIVE_FILE_MONITOR (self), NULL);

  return self->root;
}
624 625 626 627

/**
 * dzl_recursive_file_monitor_set_ignore_func:
 * @self: a #DzlRecursiveFileMonitor
628
 * @ignore_func: (scope async): a #DzlRecursiveIgnoreFunc
629 630 631 632 633 634
 * @ignore_func_data: closure data for @ignore_func
 * @ignore_func_data_destroy: destroy notify for @ignore_func_data
 *
 * Sets a callback function to determine if a #GFile should be ignored
 * from signal emission.
 *
635
 * @ignore_func will always be called from the applications main thread.
636 637 638 639 640 641 642 643 644 645 646 647
 *
 * If @ignore_func is %NULL, it is set to the default which does not
 * ignore any files or directories.
 *
 * Since: 3.28
 */
void
dzl_recursive_file_monitor_set_ignore_func (DzlRecursiveFileMonitor *self,
                                            DzlRecursiveIgnoreFunc   ignore_func,
                                            gpointer                 ignore_func_data,
                                            GDestroyNotify           ignore_func_data_destroy)
{
648
  dzl_assert_is_main_thread ();
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
  g_return_if_fail (DZL_IS_RECURSIVE_FILE_MONITOR (self));

  if (ignore_func == NULL)
    {
      ignore_func_data = NULL;
      ignore_func_data_destroy = NULL;
    }

  if (self->ignore_func_data && self->ignore_func_data_destroy)
    {
      gpointer data = self->ignore_func_data;
      GDestroyNotify notify = self->ignore_func_data_destroy;

      self->ignore_func = NULL;
      self->ignore_func_data = NULL;
      self->ignore_func_data_destroy = NULL;

      notify (data);
    }

  self->ignore_func = ignore_func;
  self->ignore_func_data = ignore_func_data;
  self->ignore_func_data_destroy = ignore_func_data_destroy;
}