Commit a84752dd authored by Sam Thursfield's avatar Sam Thursfield Committed by Debarshi Ray

base-item, utils: Avoid CRITICALs when reading an item's metadata

If the Tracker extractor has not yet run for an item then various
variables in the query will be unbound. This would led to things like:
  Tracker-CRITICAL **: tracker_sparql_cursor_real_get_integer:
    assertion 'tracker_sparql_cursor_get_value_type (self, column) ==
    TRACKER_SPARQL_VALUE_TYPE_INTEGER' failed
parent b2c17c2d
Pipeline #212563 canceled with stage
in 1 minute and 4 seconds
......@@ -2863,8 +2863,12 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
priv->orientation = PHOTOS_ORIENTATION_TOP;
}
height = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_HEIGHT);
width = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_WIDTH);
height = photos_utils_get_integer_from_sparql_cursor_with_default (cursor,
PHOTOS_QUERY_COLUMNS_HEIGHT,
0);
width = photos_utils_get_integer_from_sparql_cursor_with_default (cursor,
PHOTOS_QUERY_COLUMNS_WIDTH,
0);
if (priv->orientation == PHOTOS_ORIENTATION_BOTTOM
|| priv->orientation == PHOTOS_ORIENTATION_BOTTOM_MIRROR
|| priv->orientation == PHOTOS_ORIENTATION_TOP
......@@ -2879,10 +2883,23 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
priv->width = height;
}
priv->exposure_time = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME);
priv->fnumber = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FNUMBER);
priv->focal_length = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH);
priv->iso_speed = tracker_sparql_cursor_get_double (cursor, PHOTOS_QUERY_COLUMNS_ISO_SPEED);
priv->exposure_time
= photos_utils_get_double_from_sparql_cursor_with_default (cursor,
PHOTOS_QUERY_COLUMNS_EXPOSURE_TIME,
0.0);
priv->fnumber = photos_utils_get_double_from_sparql_cursor_with_default (cursor,
PHOTOS_QUERY_COLUMNS_FNUMBER,
0.0);
priv->focal_length
= photos_utils_get_double_from_sparql_cursor_with_default (cursor,
PHOTOS_QUERY_COLUMNS_FOCAL_LENGTH,
0.0);
priv->iso_speed = photos_utils_get_double_from_sparql_cursor_with_default (cursor,
PHOTOS_QUERY_COLUMNS_ISO_SPEED,
0.0);
flash = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FLASH, NULL);
priv->flash = g_quark_from_string (flash);
......
......@@ -917,6 +917,25 @@ photos_utils_get_controller (PhotosWindowMode mode,
}
gdouble
photos_utils_get_double_from_sparql_cursor_with_default (TrackerSparqlCursor *cursor,
PhotosQueryColumns column,
gdouble default_value)
{
TrackerSparqlValueType value_type;
gdouble ret_val = default_value;
value_type = tracker_sparql_cursor_get_value_type (cursor, column);
if (value_type == TRACKER_SPARQL_VALUE_TYPE_UNBOUND)
goto out;
ret_val = tracker_sparql_cursor_get_double (cursor, column);
out:
return ret_val;
}
gchar *
photos_utils_get_extension_from_mime_type (const gchar *mime_type)
{
......@@ -971,6 +990,25 @@ photos_utils_get_icon_size_unscaled (void)
}
gint64
photos_utils_get_integer_from_sparql_cursor_with_default (TrackerSparqlCursor *cursor,
PhotosQueryColumns column,
gint64 default_value)
{
TrackerSparqlValueType value_type;
gint64 ret_val = default_value;
value_type = tracker_sparql_cursor_get_value_type (cursor, column);
if (value_type == TRACKER_SPARQL_VALUE_TYPE_UNBOUND)
goto out;
ret_val = tracker_sparql_cursor_get_integer (cursor, column);
out:
return ret_val;
}
gint64
photos_utils_get_mtime_from_sparql_cursor (TrackerSparqlCursor *cursor)
{
......
......@@ -127,6 +127,10 @@ void photos_utils_get_controller (PhotosWindowMode mode
PhotosOffsetController **out_offset_cntrlr,
PhotosTrackerController **out_trk_cntrlr);
gdouble photos_utils_get_double_from_sparql_cursor_with_default (TrackerSparqlCursor *cursor,
PhotosQueryColumns column,
gdouble default_value);
gchar *photos_utils_get_extension_from_mime_type (const gchar *mime_type);
......@@ -134,6 +138,10 @@ gint photos_utils_get_icon_size (void);
gint photos_utils_get_icon_size_unscaled (void);
gint64 photos_utils_get_integer_from_sparql_cursor_with_default (TrackerSparqlCursor *cursor,
PhotosQueryColumns column,
gint64 default_value);
gint64 photos_utils_get_mtime_from_sparql_cursor (TrackerSparqlCursor *cursor);
char* photos_utils_get_pixbuf_common_suffix (GdkPixbufFormat *format);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment