From 8ba2ebb450ea70159a8afe3d6995eec7f1fc8d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Sat, 8 Apr 2023 22:41:58 +0100 Subject: search-engine-tracker: Don't try to parse NULL time strings TrackerCursor returns NULL if it doesn't have information on the date. https://gnome.pages.gitlab.gnome.org/tracker/docs/developer/method.SparqlCursor.get_string.html We try to parse NULL as a date string. This is obviously wrong and gets us a precondition failure warning, as it should. So, if a string is NULL, just skip it. Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2160 --- src/nautilus-search-engine-tracker.c | 45 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c index 51917216b..88bd376c2 100644 --- a/src/nautilus-search-engine-tracker.c +++ b/src/nautilus-search-engine-tracker.c @@ -181,7 +181,6 @@ cursor_callback (GObject *object, const char *atime_str; const char *ctime_str; const gchar *snippet; - GDateTime *date; g_autoptr (GTimeZone) tz = g_time_zone_new_local (); gdouble rank, match; gboolean success; @@ -232,35 +231,37 @@ cursor_callback (GObject *object, } } - date = g_date_time_new_from_iso8601 (mtime_str, tz); - if (date != NULL) + if (mtime_str != NULL) { + g_autoptr (GDateTime) date = g_date_time_new_from_iso8601 (mtime_str, tz); + + if (date == NULL) + { + g_warning ("unable to parse mtime: %s", mtime_str); + } nautilus_search_hit_set_modification_time (hit, date); - g_date_time_unref (date); - } - else - { - g_warning ("unable to parse mtime: %s", mtime_str); } - date = g_date_time_new_from_iso8601 (atime_str, tz); - if (date != NULL) + + if (atime_str != NULL) { + g_autoptr (GDateTime) date = g_date_time_new_from_iso8601 (atime_str, tz); + + if (date == NULL) + { + g_warning ("unable to parse atime: %s", atime_str); + } nautilus_search_hit_set_access_time (hit, date); - g_date_time_unref (date); } - else - { - g_warning ("unable to parse atime: %s", atime_str); - } - date = g_date_time_new_from_iso8601 (ctime_str, tz); - if (date != NULL) + + if (ctime_str != NULL) { + g_autoptr (GDateTime) date = g_date_time_new_from_iso8601 (ctime_str, tz); + + if (date == NULL) + { + g_warning ("unable to parse ctime: %s", ctime_str); + } nautilus_search_hit_set_creation_time (hit, date); - g_date_time_unref (date); - } - else - { - g_warning ("unable to parse ctime: %s", ctime_str); } g_queue_push_head (tracker->hits_pending, hit); -- cgit v1.2.1