Ignore if an entry cannot be read when enumerating files
[cascardo/atompub.git] / backend / gio / gio.c
index f430f84..7f140a6 100644 (file)
@@ -73,14 +73,24 @@ gio_enumerate_entries (AtomCtx *ctx, AtomEntry ***entries, size_t *len)
   GFileEnumerator *enumerator;
   GFileInfo *info;
   GFile *file;
+  AtomEntry *entry;
+  GError *error;
   gchar *root;
   gchar *name;
   gchar *filename;
   GPtrArray *array;
   root = atom_config_get_str (ctx, "gio", "root");
   dir = g_file_new_for_path (root);
+  error = NULL;
   enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME,
-                                         G_FILE_QUERY_INFO_NONE, NULL, NULL);
+                                         G_FILE_QUERY_INFO_NONE, NULL, &error);
+  if (enumerator == NULL)
+    {
+      AtomError *aerr = atom_error_new_from_gerror (error);
+      atom_error_set (ctx, aerr);
+      g_error_free (error);
+      return;
+    }
   array = g_ptr_array_new ();
   while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
     {
@@ -88,7 +98,15 @@ gio_enumerate_entries (AtomCtx *ctx, AtomEntry ***entries, size_t *len)
       filename = g_build_filename (root, name, NULL);
       g_object_unref (info);
       file = g_file_new_for_path (filename);
-      g_ptr_array_add (array, gio_file_to_atom (ctx, file));
+      entry = gio_file_to_atom (ctx, file);
+      if (entry)
+        {
+          g_ptr_array_add (array, entry);
+        }
+      else
+        {
+          atom_error_set (ctx, NULL);
+        }
       g_object_unref (file);
       g_free (filename);
     }