diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2022-05-08 00:08:50 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2022-06-30 23:57:43 +0200 |
commit | 14a7bff63ccf72b1c03291198bb2c89eba93ba66 (patch) | |
tree | 5692146f6515a78a5a5c51178be27207539edb2d /src/tracker | |
parent | 3260379e9c51812b0881026cb636c82d4a6d0fb3 (diff) | |
download | tracker-14a7bff63ccf72b1c03291198bb2c89eba93ba66.tar.gz |
cli: Update tracker-import to use deserialization API
Exercise the new API in the import tool.
Diffstat (limited to 'src/tracker')
-rw-r--r-- | src/tracker/tracker-import.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/tracker/tracker-import.c b/src/tracker/tracker-import.c index 6d35fb1b4..30d7f913a 100644 --- a/src/tracker/tracker-import.c +++ b/src/tracker/tracker-import.c @@ -85,11 +85,31 @@ create_connection (GError **error) } } +static void +deserialize_cb (GObject *source, + GAsyncResult *res, + gpointer user_data) +{ + GError *error = NULL; + + if (!tracker_sparql_connection_deserialize_finish (TRACKER_SPARQL_CONNECTION (source), + res, &error)) { + g_printerr ("%s, %s\n", + _("Could not run import"), + error->message); + exit (EXIT_FAILURE); + } + + g_main_loop_quit (user_data); +} + static int import_run (void) { g_autoptr(TrackerSparqlConnection) connection = NULL; g_autoptr(GError) error = NULL; + g_autoptr(GMainLoop) main_loop = NULL; + g_autoptr(GInputStream) stream = NULL; gchar **p; connection = create_connection (&error); @@ -101,17 +121,16 @@ import_run (void) return EXIT_FAILURE; } + main_loop = g_main_loop_new (NULL, FALSE); + for (p = filenames; *p; p++) { g_autoptr(GFile) file = NULL; g_autofree gchar *update = NULL; g_autofree gchar *uri = NULL; file = g_file_new_for_commandline_arg (*p); - uri = g_file_get_uri (file); - update = g_strdup_printf ("LOAD <%s>", uri); - - tracker_sparql_connection_update (connection, update, NULL, &error); + stream = G_INPUT_STREAM (g_file_read (file, NULL, &error)); if (error) { g_printerr ("%s, %s\n", _("Could not run import"), @@ -119,6 +138,16 @@ import_run (void) return EXIT_FAILURE; } + tracker_sparql_connection_deserialize_async (connection, + TRACKER_DESERIALIZE_FLAGS_NONE, + TRACKER_RDF_FORMAT_TURTLE, + NULL, + stream, + NULL, + deserialize_cb, + main_loop); + g_main_loop_run (main_loop); + g_print ("Successfully imported %s", g_file_peek_path (file)); } |