Add GError to file monitor calls
authorAlexander Larsson <alexl@redhat.com>
Mon, 14 Jan 2008 15:00:31 +0000 (15:00 +0000)
committerAlexander Larsson <alexl@src.gnome.org>
Mon, 14 Jan 2008 15:00:31 +0000 (15:00 +0000)
2008-01-14  Alexander Larsson  <alexl@redhat.com>

        * gfile.[ch]:
        (g_file_monitor_directory):
        (g_file_monitor_file):
Add GError to file monitor calls

        * glocaldirectorymonitor.c:
        * glocaldirectorymonitor.h:
        * glocalfile.c:
        * glocalfilemonitor.c:
        * glocalfilemonitor.h:
        * gunixmounts.c:
Update for above change

svn path=/trunk/; revision=6306

gio/ChangeLog
gio/gfile.c
gio/gfile.h
gio/glocaldirectorymonitor.c
gio/glocaldirectorymonitor.h
gio/glocalfile.c
gio/glocalfilemonitor.c
gio/glocalfilemonitor.h
gio/gunixmounts.c

index 5a7ae0a..d88c45f 100644 (file)
@@ -1,5 +1,20 @@
 2008-01-14  Alexander Larsson  <alexl@redhat.com>
 
+        * gfile.[ch]:
+        (g_file_monitor_directory):
+        (g_file_monitor_file):
+       Add GError to file monitor calls
+       
+        * glocaldirectorymonitor.c:
+        * glocaldirectorymonitor.h:
+        * glocalfile.c:
+        * glocalfilemonitor.c:
+        * glocalfilemonitor.h:
+        * gunixmounts.c:
+       Update for above change
+
+2008-01-14  Alexander Larsson  <alexl@redhat.com>
+
         * glocalfile.c:
         (match_prefix):
        Handle root correctly in g_file_get_relative_path (#508719)
index 185081f..0d0a5e1 100644 (file)
@@ -3249,6 +3249,7 @@ g_file_eject_mountable_finish (GFile         *file,
  * @file: input #GFile.
  * @flags: a set of #GFileMonitorFlags.
  * @cancellable: optional #GCancellable object, %NULL to ignore.
+ * @error: a #GError, or %NULL.
  * 
  * Obtains a directory monitor for the given file.
  * This may fail if directory monitoring is not supported.
@@ -3263,18 +3264,27 @@ g_file_eject_mountable_finish (GFile         *file,
 GFileMonitor*
 g_file_monitor_directory (GFile             *file,
                          GFileMonitorFlags  flags,
-                         GCancellable      *cancellable)
+                         GCancellable      *cancellable,
+                         GError           **error)
 {
   GFileIface *iface;
 
   g_return_val_if_fail (G_IS_FILE (file), NULL);
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return NULL;
+
   iface = G_FILE_GET_IFACE (file);
 
   if (iface->monitor_dir == NULL)
-    return NULL;
+    {
+      g_set_error (error, G_IO_ERROR,
+                  G_IO_ERROR_NOT_SUPPORTED,
+                  _("Operation not supported"));
+      return NULL;
+    }
 
-  return (* iface->monitor_dir) (file, flags, cancellable);
+  return (* iface->monitor_dir) (file, flags, cancellable, error);
 }
 
 /**
@@ -3282,6 +3292,7 @@ g_file_monitor_directory (GFile             *file,
  * @file: input #GFile.
  * @flags: a set of #GFileMonitorFlags.
  * @cancellable: optional #GCancellable object, %NULL to ignore.
+ * @error: a #GError, or %NULL.
  * 
  * Obtains a file monitor for the given file. If no file notification
  * mechanism exists, then regular polling of the file is used.
@@ -3295,19 +3306,23 @@ g_file_monitor_directory (GFile             *file,
 GFileMonitor*
 g_file_monitor_file (GFile             *file,
                     GFileMonitorFlags  flags,
-                    GCancellable      *cancellable)
+                    GCancellable      *cancellable,
+                    GError           **error)
 {
   GFileIface *iface;
   GFileMonitor *monitor;
   
   g_return_val_if_fail (G_IS_FILE (file), NULL);
 
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return NULL;
+
   iface = G_FILE_GET_IFACE (file);
 
   monitor = NULL;
   
   if (iface->monitor_file)
-    monitor = (* iface->monitor_file) (file, flags, cancellable);
+    monitor = (* iface->monitor_file) (file, flags, cancellable, error);
 
 /* Fallback to polling */
   if (monitor == NULL)
index 6ad47fe..0fd5718 100644 (file)
@@ -518,11 +518,13 @@ struct _GFileIface
   
   GFileMonitor*      (*monitor_dir)         (GFile                  *file,
                                             GFileMonitorFlags       flags,
-                                            GCancellable           *cancellable);
+                                            GCancellable           *cancellable,
+                                            GError                **error);
 
   GFileMonitor*      (*monitor_file)        (GFile                  *file,
                                             GFileMonitorFlags       flags,
-                                            GCancellable           *cancellable);
+                                            GCancellable           *cancellable,
+                                            GError                **error);
 
 };
 
@@ -794,10 +796,12 @@ gboolean                g_file_copy_attributes            (GFile
 
 GFileMonitor*           g_file_monitor_directory          (GFile                  *file,
                                                           GFileMonitorFlags       flags,
-                                                          GCancellable           *cancellable);
+                                                          GCancellable           *cancellable,
+                                                          GError                **error);
 GFileMonitor*           g_file_monitor_file               (GFile                  *file,
                                                           GFileMonitorFlags       flags,
-                                                          GCancellable           *cancellable);
+                                                          GCancellable           *cancellable,
+                                                          GError                **error);
 
 
 /* Utilities */
index 92eac73..435dcaf 100644 (file)
@@ -276,8 +276,9 @@ get_default_local_directory_monitor (gpointer data)
  * Returns: new #GFileMonitor for the given @dirname.
  **/
 GFileMonitor*
-_g_local_directory_monitor_new (const char*       dirname,
-                               GFileMonitorFlags flags)
+_g_local_directory_monitor_new (const char         *dirname,
+                               GFileMonitorFlags   flags,
+                               GError            **error)
 {
   static GOnce once_init = G_ONCE_INIT;
   GTypeClass *type_class;
@@ -291,6 +292,8 @@ _g_local_directory_monitor_new (const char*       dirname,
   monitor = NULL;
   if (type != G_TYPE_INVALID)
     monitor = G_FILE_MONITOR (g_object_new (type, "dirname", dirname, NULL));
+  else
+    g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Unable to find default local directory monitor type"));
 
   /* This is non-null on first pass here. Unref the class now.
    * This is to avoid unloading the module and then loading it
index 79deb47..40923e6 100644 (file)
@@ -59,7 +59,8 @@ struct _GLocalDirectoryMonitorClass {
 GType g_local_directory_monitor_get_type (void) G_GNUC_CONST;
 
 GFileMonitor* _g_local_directory_monitor_new (const char* dirname,
-                                             GFileMonitorFlags flags);
+                                             GFileMonitorFlags flags,
+                                             GError **error);
 
 G_END_DECLS
 
index 1de3e48..2b4b35e 100644 (file)
@@ -1861,19 +1861,21 @@ g_local_file_move (GFile                  *source,
 static GFileMonitor*
 g_local_file_monitor_dir (GFile             *file,
                          GFileMonitorFlags  flags,
-                         GCancellable      *cancellable)
+                         GCancellable      *cancellable,
+                         GError           **error)
 {
   GLocalFile* local_file = G_LOCAL_FILE(file);
-  return _g_local_directory_monitor_new (local_file->filename, flags);
+  return _g_local_directory_monitor_new (local_file->filename, flags, error);
 }
 
 static GFileMonitor*
 g_local_file_monitor_file (GFile             *file,
                           GFileMonitorFlags  flags,
-                          GCancellable      *cancellable)
+                          GCancellable      *cancellable,
+                          GError           **error)
 {
   GLocalFile* local_file = G_LOCAL_FILE(file);
-  return _g_local_file_monitor_new (local_file->filename, flags);
+  return _g_local_file_monitor_new (local_file->filename, flags, error);
 }
 
 static void
index 6ca67a5..bdacebf 100644 (file)
@@ -205,8 +205,9 @@ get_default_local_file_monitor (gpointer data)
  * Returns: a new #GFileMonitor for the given @pathname. 
  **/
 GFileMonitor*
-_g_local_file_monitor_new (const char        *pathname,
-                          GFileMonitorFlags  flags)
+_g_local_file_monitor_new (const char         *pathname,
+                          GFileMonitorFlags   flags,
+                          GError            **error)
 {
   static GOnce once_init = G_ONCE_INIT;
   GTypeClass *type_class;
@@ -220,6 +221,8 @@ _g_local_file_monitor_new (const char        *pathname,
   monitor = NULL;
   if (type != G_TYPE_INVALID)
     monitor = G_FILE_MONITOR (g_object_new (type, "filename", pathname, NULL));
+  else
+    g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Unable to find default local file monitor type"));
 
   /* This is non-null on first pass here. Unref the class now.
    * This is to avoid unloading the module and then loading it
index e01ab06..658310d 100644 (file)
@@ -53,7 +53,8 @@ struct _GLocalFileMonitorClass {
 GType g_local_file_monitor_get_type (void) G_GNUC_CONST;
 
 GFileMonitor* _g_local_file_monitor_new (const char* pathname,
-                                        GFileMonitorFlags flags);
+                                        GFileMonitorFlags flags,
+                                        GError **error);
 
 G_END_DECLS
 
index f2b0de2..d761b2e 100644 (file)
@@ -1191,7 +1191,7 @@ g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
   if (get_fstab_file () != NULL)
     {
       file = g_file_new_for_path (get_fstab_file ());
-      monitor->fstab_monitor = g_file_monitor_file (file, 0, NULL);
+      monitor->fstab_monitor = g_file_monitor_file (file, 0, NULL, NULL);
       g_object_unref (file);
       
       g_signal_connect (monitor->fstab_monitor, "changed", (GCallback)fstab_file_changed, monitor);
@@ -1200,7 +1200,7 @@ g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
   if (get_mtab_monitor_file () != NULL)
     {
       file = g_file_new_for_path (get_mtab_monitor_file ());
-      monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL);
+      monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL, NULL);
       g_object_unref (file);
       
       g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor);