[gnome-software] Do not overwrite high quality licensing data with lower quality data



commit 5a64755253e062c5d24879ff71079b6eed13f369
Author: Richard Hughes <richard hughsie com>
Date:   Wed Dec 9 10:57:06 2015 +0000

    Do not overwrite high quality licensing data with lower quality data
    
    In this example, AppStream has SPDX information for us, but the packaging
    system might be returning Fedora-style data or something else entirely.
    
    Note: We *have* to get the license data from the package system sometimes, in
    the case of an installed application without an AppData file.

 src/gs-app.c                               |    8 +++++++-
 src/gs-app.h                               |    3 ++-
 src/plugins/gs-plugin-appstream.c          |    4 +++-
 src/plugins/gs-plugin-packagekit-refine.c  |    7 +++++--
 src/plugins/gs-plugin-packagekit-refresh.c |    2 +-
 5 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index 3bab13c..883db8a 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -73,6 +73,7 @@ struct _GsApp
        GPtrArray               *keywords;
        GHashTable              *urls;
        gchar                   *licence;
+       GsAppQuality             licence_quality;
        gchar                   **menu_path;
        gchar                   *origin;
        gchar                   *update_version;
@@ -1286,12 +1287,17 @@ gs_app_get_licence (GsApp *app)
  * gs_app_set_licence:
  */
 void
-gs_app_set_licence (GsApp *app, const gchar *licence)
+gs_app_set_licence (GsApp *app, const gchar *licence, GsAppQuality quality)
 {
        GString *urld;
        guint i;
        g_auto(GStrv) tokens = NULL;
 
+       /* only save this if the data is sufficiently high quality */
+       if (quality <= app->licence_quality)
+               return;
+       app->licence_quality = quality;
+
        g_return_if_fail (GS_IS_APP (app));
 
        /* tokenize the license string and URLify any SPDX IDs */
diff --git a/src/gs-app.h b/src/gs-app.h
index a69f4c0..ca01712 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -167,7 +167,8 @@ void                 gs_app_set_url                 (GsApp          *app,
                                                 const gchar    *url);
 const gchar    *gs_app_get_licence             (GsApp          *app);
 void            gs_app_set_licence             (GsApp          *app,
-                                                const gchar    *licence);
+                                                const gchar    *licence,
+                                                GsAppQuality    quality);
 gchar          **gs_app_get_menu_path          (GsApp          *app);
 void            gs_app_set_menu_path           (GsApp          *app,
                                                 gchar          **menu_path);
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index 1b9cd3b..84593b4 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -567,7 +567,9 @@ gs_plugin_refine_item (GsPlugin *plugin,
 
        /* set licence */
        if (as_app_get_project_license (item) != NULL && gs_app_get_licence (app) == NULL)
-               gs_app_set_licence (app, as_app_get_project_license (item));
+               gs_app_set_licence (app,
+                                   as_app_get_project_license (item),
+                                   GS_APP_QUALITY_HIGHEST);
 
        /* set keywords */
        if (as_app_get_keywords (item, NULL) != NULL &&
diff --git a/src/plugins/gs-plugin-packagekit-refine.c b/src/plugins/gs-plugin-packagekit-refine.c
index e4ec3b0..8ed3195 100644
--- a/src/plugins/gs-plugin-packagekit-refine.c
+++ b/src/plugins/gs-plugin-packagekit-refine.c
@@ -499,8 +499,11 @@ gs_plugin_packagekit_refine_details_app (GsPlugin *plugin,
                                                pk_details_get_package_id (details))) {
                                continue;
                        }
-                       if (gs_app_get_licence (app) == NULL)
-                               gs_app_set_licence (app, pk_details_get_license (details));
+                       if (gs_app_get_licence (app) == NULL) {
+                               gs_app_set_licence (app,
+                                                   pk_details_get_license (details),
+                                                   GS_APP_QUALITY_LOWEST);
+                       }
                        if (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE) == NULL) {
                                gs_app_set_url (app,
                                                AS_URL_KIND_HOMEPAGE,
diff --git a/src/plugins/gs-plugin-packagekit-refresh.c b/src/plugins/gs-plugin-packagekit-refresh.c
index 45753ab..f4518eb 100644
--- a/src/plugins/gs-plugin-packagekit-refresh.c
+++ b/src/plugins/gs-plugin-packagekit-refresh.c
@@ -374,7 +374,7 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
                                               pk_details_get_description (item));
        gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, pk_details_get_url (item));
        gs_app_set_size (app, pk_details_get_size (item));
-       gs_app_set_licence (app, pk_details_get_license (item));
+       gs_app_set_licence (app, pk_details_get_license (item), GS_APP_QUALITY_LOWEST);
 
        /* look for a desktop file so we can use a valid application id */
        if (!gs_plugin_packagekit_refresh_guess_app_id (plugin,


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