[glib/wip/mount-watcher: 17/24] GFileMonitor: get rid of APPEARED events



commit 9b49073f012a2c8c6358ee59acf00817a4532f84
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jan 15 11:28:40 2015 -0500

    GFileMonitor: get rid of APPEARED events
    
    We could accomplish what we want by simply reporting CREATED directly
    followed by CHANGES_DONE.
    
    We may want to add back _APPEARED some day and allow people to opt into
    it separately via a GFileMonitorFlag if they really care about the
    distinction.  It would certainly be nicer to allow the backends to
    report this case with a distinct event type and have GFileMonitorSource
    do the right thing.

 gio/gio.c                    |    4 ----
 gio/gioenums.h               |    1 -
 gio/glocalfilemonitor.c      |    8 --------
 gio/inotify/inotify-helper.c |   34 ++++++++++++++++++----------------
 4 files changed, 18 insertions(+), 29 deletions(-)
---
diff --git a/gio/gio.c b/gio/gio.c
index ad2de1c..0f06649 100644
--- a/gio/gio.c
+++ b/gio/gio.c
@@ -67,10 +67,6 @@ gio_watch_callback (GFileMonitor      *monitor,
       g_assert (!other);
       g_print ("%s: deleted", child_str);
       break;
-    case G_FILE_MONITOR_EVENT_APPEARED:
-      g_assert (!other);
-      g_print ("%s: appeared", child_str);
-      break;
     case G_FILE_MONITOR_EVENT_CREATED:
       g_assert (!other);
       g_print ("%s: created", child_str);
diff --git a/gio/gioenums.h b/gio/gioenums.h
index f78d1a0..9fd563d 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -422,7 +422,6 @@ typedef enum {
   G_FILE_MONITOR_EVENT_PRE_UNMOUNT,
   G_FILE_MONITOR_EVENT_UNMOUNTED,
   G_FILE_MONITOR_EVENT_MOVED,
-  G_FILE_MONITOR_EVENT_APPEARED,
   G_FILE_MONITOR_EVENT_RENAMED,
   G_FILE_MONITOR_EVENT_MOVED_IN,
   G_FILE_MONITOR_EVENT_MOVED_OUT
diff --git a/gio/glocalfilemonitor.c b/gio/glocalfilemonitor.c
index 8a76037..44b24a6 100644
--- a/gio/glocalfilemonitor.c
+++ b/gio/glocalfilemonitor.c
@@ -387,14 +387,6 @@ g_file_monitor_source_handle_event (GFileMonitorSource *fms,
         }
       break;
 
-    case G_FILE_MONITOR_EVENT_APPEARED:
-      g_assert (!other && !rename_to);
-      if (fms->flags & G_FILE_MONITOR_WATCH_MOVES)
-        g_file_monitor_source_send_event (fms, event_type, child, NULL);
-      else
-        g_file_monitor_source_send_synthetic_created (fms, child);
-      break;
-
     case G_FILE_MONITOR_EVENT_DELETED:
     case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
     case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
diff --git a/gio/inotify/inotify-helper.c b/gio/inotify/inotify-helper.c
index c4c1bed..9e52f60 100644
--- a/gio/inotify/inotify-helper.c
+++ b/gio/inotify/inotify-helper.c
@@ -194,9 +194,13 @@ ih_event_callback (ik_event_t  *event,
             g_object_unref (other);
         }
     }
-  else if (event->mask & IN_CREATE)
+  else
+    /* unpaired event -- no 'other' field */
+    g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
+                                        event->name, NULL, NULL, event->timestamp);
+
+  if (event->mask & IN_CREATE)
     {
-      GFileMonitorEvent event_type;
       const gchar *parent_dir;
       gchar *fullname;
       struct stat buf;
@@ -207,8 +211,8 @@ ih_event_callback (ik_event_t  *event,
        *  - creat(), in which case IN_CLOSE_WRITE will come soon; or
        *  - link(), mkdir(), mknod(), etc., in which case it won't
        *
-       * We can attempt to detect the second case and turn it into an
-       * APPEARED event so that the user isn't expecting CHANGES_DONE.
+       * We can attempt to detect the second case and send the
+       * CHANGES_DONE immediately so that the user isn't left waiting.
        *
        * The detection for link() is not 100% reliable since the link
        * count could be 1 if the original link was deleted or if
@@ -221,24 +225,22 @@ ih_event_callback (ik_event_t  *event,
       s = stat (fullname, &buf);
       g_free (fullname);
 
-      /* does it look like the result of creat()? */
-      if (s == 0 && S_ISREG (buf.st_mode) && buf.st_nlink == 1)
-        event_type = G_FILE_MONITOR_EVENT_CREATED;
-      else
-        event_type = G_FILE_MONITOR_EVENT_APPEARED;
-
-      g_file_monitor_source_handle_event (sub->user_data, event_type, event->name, NULL, NULL, 
event->timestamp);
+      /* if it doesn't look like the result of creat()... */
+      if (s != 0 || !S_ISREG (buf.st_mode) || buf.st_nlink != 1)
+        g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT,
+                                            event->name, NULL, NULL, event->timestamp);
     }
-  else
-    g_file_monitor_source_handle_event (sub->user_data, ih_mask_to_EventFlags (event->mask),
-                                        event->name, NULL, NULL, event->timestamp);
 }
 
 static void
 ih_not_missing_callback (inotify_sub *sub)
 {
-  g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_APPEARED,
-                                      sub->filename, NULL, NULL, g_get_monotonic_time ());
+  gint now = g_get_monotonic_time ();
+
+  g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_CREATED,
+                                      sub->filename, NULL, NULL, now);
+  g_file_monitor_source_handle_event (sub->user_data, G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT,
+                                      sub->filename, NULL, NULL, now);
 }
 
 /* Transforms a inotify event to a GVFS event. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]