[gnome-photos] utils: Be robust against PhotosTrackerQueue failures



commit c3f00239da24974bc71e9597a48c51fc822c7b5c
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Dec 27 18:46:31 2013 +0100

    utils: Be robust against PhotosTrackerQueue failures
    
    Fixes: https://bugzilla.gnome.org/704947

 src/photos-utils.c |   37 ++++++++++++++++++++++++++++++-------
 1 files changed, 30 insertions(+), 7 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index e9bec14..e5b028e 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -653,13 +653,25 @@ photos_utils_update_executed (GObject *source_object, GAsyncResult *res, gpointe
 void
 photos_utils_set_edited_name (const gchar *urn, const gchar *title)
 {
-  PhotosTrackerQueue *queue;
-  gchar *sparql;
+  GError *error;
+  PhotosTrackerQueue *queue = NULL;
+  gchar *sparql = NULL;
 
   sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:title \"%s\" }", urn, title);
-  queue = photos_tracker_queue_dup_singleton (NULL, NULL);
+
+  error = NULL;
+  queue = photos_tracker_queue_dup_singleton (NULL, &error);
+  if (G_UNLIKELY (error != NULL))
+    {
+      g_warning ("Unable to set edited name %s: %s", urn, error->message);
+      g_error_free (error);
+      goto out;
+    }
+
   photos_tracker_queue_update (queue, sparql, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
-  g_object_unref (queue);
+
+ out:
+  g_clear_object (&queue);
   g_free (sparql);
 }
 
@@ -667,14 +679,25 @@ photos_utils_set_edited_name (const gchar *urn, const gchar *title)
 void
 photos_utils_set_favorite (const gchar *urn, gboolean is_favorite)
 {
-  PhotosTrackerQueue *queue;
+  GError *error;
+  PhotosTrackerQueue *queue = NULL;
   gchar *sparql;
 
   sparql = g_strdup_printf ("%s { <%s> nao:hasTag nao:predefined-tag-favorite }",
                             (is_favorite) ? "INSERT OR REPLACE" : "DELETE",
                             urn);
 
-  queue = photos_tracker_queue_dup_singleton (NULL, NULL);
+  error = NULL;
+  queue = photos_tracker_queue_dup_singleton (NULL, &error);
+  if (G_UNLIKELY (error != NULL))
+    {
+      g_warning ("Unable to set favorite %s: %s", urn, error->message);
+      g_error_free (error);
+      goto out;
+    }
+
   photos_tracker_queue_update (queue, sparql, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
-  g_object_unref (queue);
+
+ out:
+  g_clear_object (&queue);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]