[gnome-software: 3/6] gs-appstream: Fix requires relations being ignored if no recommends exist




commit 6ee7b072cb594342cda270e40d29521f5883b5ab
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed May 25 12:13:17 2022 +0100

    gs-appstream: Fix requires relations being ignored if no recommends exist
    
    Spotted by Milan Crha in
    https://gitlab.gnome.org/GNOME/gnome-software/-/merge_requests/1379#note_1463083.
    
    Any `<requires>` elements were being ignored if no `<recommends>`
    elements were present, as the query for the latter would have returned
    `G_IO_ERROR_NOT_FOUND`.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 lib/gs-appstream.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/lib/gs-appstream.c b/lib/gs-appstream.c
index e9329feeb..025771900 100644
--- a/lib/gs-appstream.c
+++ b/lib/gs-appstream.c
@@ -931,29 +931,29 @@ gs_appstream_refine_app_relations (GsApp     *app,
 
        /* find any recommends */
        recommends = xb_node_query (component, "recommends", 0, &error_local);
-       if (recommends == NULL) {
-               if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
-                       return TRUE;
+       if (recommends == NULL &&
+           !g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
                g_propagate_error (error, g_steal_pointer (&error_local));
                return FALSE;
        }
 
-       for (guint i = 0; i < recommends->len; i++) {
+       for (guint i = 0; recommends != NULL && i < recommends->len; i++) {
                XbNode *recommend = g_ptr_array_index (recommends, i);
                if (!gs_appstream_refine_app_relation (app, recommend, AS_RELATION_KIND_RECOMMENDS, error))
                        return FALSE;
        }
 
+       g_clear_error (&error_local);
+
        /* find any requires */
        requires = xb_node_query (component, "requires", 0, &error_local);
-       if (requires == NULL) {
-               if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
-                       return TRUE;
+       if (requires == NULL &&
+           !g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) {
                g_propagate_error (error, g_steal_pointer (&error_local));
                return FALSE;
        }
 
-       for (guint i = 0; i < requires->len; i++) {
+       for (guint i = 0; requires != NULL && i < requires->len; i++) {
                XbNode *require = g_ptr_array_index (requires, i);
                if (!gs_appstream_refine_app_relation (app, require, AS_RELATION_KIND_REQUIRES, error))
                        return FALSE;


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