When enumerating entries, return the requests backend understands
[cascardo/atompub.git] / backend / gio / gio.c
index f430f84..095345b 100644 (file)
@@ -67,39 +67,64 @@ gio_atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
 }
 
 static void
-gio_enumerate_entries (AtomCtx *ctx, AtomEntry ***entries, size_t *len)
+gio_enumerate_entries (AtomCtx *ctx, char ***reqs, AtomEntry ***entries,
+                      size_t *len)
 {
   GFile *dir;
   GFileEnumerator *enumerator;
   GFileInfo *info;
   GFile *file;
+  AtomEntry *entry;
+  GError *error;
   gchar *root;
   gchar *name;
   gchar *filename;
   GPtrArray *array;
+  GPtrArray *filenames;
   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 ();
+  filenames = g_ptr_array_new ();
   while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
     {
       name = g_file_info_get_name (info);
       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);
+          g_ptr_array_add (filenames, g_strdup (name));
+        }
+      else
+        {
+          atom_error_set (ctx, NULL);
+        }
       g_object_unref (file);
       g_free (filename);
     }
   g_object_unref (enumerator);
   g_object_unref (dir);
   g_free (root);
+  if (reqs)
+    *reqs = filenames->pdata;
   if (entries)
     *entries = array->pdata;
   if (len)
     *len = array->len;
   g_ptr_array_free (array, FALSE);
+  g_ptr_array_free (filenames, FALSE);
 }
 
 static int