#include <gio/gio.h>
#include <atompub/atom.h>
#include <atompub/atom-glib.h>
+#include <string.h>
static GFile *
-gio_iri_to_file (AtomCtx *ctx, IRI *iri)
+gio_id_to_file (AtomCtx *ctx, AtomID *id)
{
gchar *root = atom_config_get_str (ctx, "gio", "root");
- gchar *path = iri_get_path (iri);
+ gchar *path = atom_id_string (id);
gchar *filename = g_build_filename (root, path, NULL);
GFile *file = g_file_new_for_path (filename);
g_free (root);
}
static AtomEntry *
-gio_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+gio_atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
{
GFile *file;
AtomEntry *atom;
- file = gio_iri_to_file (ctx, iri);
+ file = gio_id_to_file (ctx, id);
atom = gio_file_to_atom (ctx, file);
g_object_unref (file);
return atom;
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)
{
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);
}
g_ptr_array_free (array, FALSE);
}
+static int
+gio_atom_is_feed (AtomCtx *ctx, AtomID *id)
+{
+ return (!strcmp (atom_id_string (id), "/"));
+}
+
AtomBackend *
gio_backend (void)
{
AtomBackend *backend;
backend = atom_backend_new ();
- atom_backend_retrieve_resource_set (backend, gio_atom_retrieve_resource);
+ atom_backend_retrieve_entry_set (backend, gio_atom_retrieve_entry);
atom_backend_enumerate_entries_set (backend, gio_enumerate_entries);
+ atom_backend_is_feed_set (backend, gio_atom_is_feed);
return backend;
}