[gnome-software] Remove the duplicate application with the lowest priority
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Remove the duplicate application with the lowest priority
- Date: Wed, 16 Oct 2013 19:48:19 +0000 (UTC)
commit 34b082ac28eff6153350ad8dd0c5628232c63223
Author: Richard Hughes <richard hughsie com>
Date: Wed Oct 16 20:47:30 2013 +0100
Remove the duplicate application with the lowest priority
We might want certain repo metadata to prioritized over other repos, for
instance where an application is available in two different versions.
src/plugins/appstream-app.c | 20 ++++++++++++++++++++
src/plugins/appstream-app.h | 3 +++
src/plugins/appstream-cache.c | 33 ++++++++++++++++++++++++++++++---
src/plugins/appstream-common.c | 4 ++++
src/plugins/appstream-common.h | 1 +
5 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/src/plugins/appstream-app.c b/src/plugins/appstream-app.c
index 69a909d..026a034 100644
--- a/src/plugins/appstream-app.c
+++ b/src/plugins/appstream-app.c
@@ -31,6 +31,7 @@ struct AppstreamApp
{
gchar *id;
gchar *pkgname;
+ gint priority;
gchar *name;
guint name_value;
gchar *summary;
@@ -114,6 +115,7 @@ appstream_app_new (void)
app->description_value = G_MAXUINT;
app->icon_kind = APPSTREAM_APP_ICON_KIND_UNKNOWN;
app->id_kind = APPSTREAM_APP_ID_KIND_UNKNOWN;
+ app->priority = 0;
return app;
}
@@ -136,6 +138,15 @@ appstream_app_get_pkgname (AppstreamApp *app)
}
/**
+ * appstream_app_get_priority:
+ */
+gint
+appstream_app_get_priority (AppstreamApp *app)
+{
+ return app->priority;
+}
+
+/**
* appstream_app_get_name:
*/
const gchar *
@@ -290,6 +301,15 @@ appstream_app_set_pkgname (AppstreamApp *app,
}
/**
+ * appstream_app_set_priority:
+ */
+void
+appstream_app_set_priority (AppstreamApp *app, gint priority)
+{
+ app->priority = priority;
+}
+
+/**
* appstream_app_set_name:
*/
void
diff --git a/src/plugins/appstream-app.h b/src/plugins/appstream-app.h
index e183e45..f1a865a 100644
--- a/src/plugins/appstream-app.h
+++ b/src/plugins/appstream-app.h
@@ -51,6 +51,7 @@ AppstreamApp *appstream_app_new (void);
const gchar *appstream_app_get_id (AppstreamApp *app);
const gchar *appstream_app_get_pkgname (AppstreamApp *app);
+gint appstream_app_get_priority (AppstreamApp *app);
const gchar *appstream_app_get_name (AppstreamApp *app);
const gchar *appstream_app_get_summary (AppstreamApp *app);
const gchar *appstream_app_get_project_group (AppstreamApp *app);
@@ -71,6 +72,8 @@ void appstream_app_set_id (AppstreamApp *app,
void appstream_app_set_pkgname (AppstreamApp *app,
const gchar *pkgname,
gsize length);
+void appstream_app_set_priority (AppstreamApp *app,
+ gint priority);
void appstream_app_set_name (AppstreamApp *app,
const gchar *lang,
const gchar *name,
diff --git a/src/plugins/appstream-cache.c b/src/plugins/appstream-cache.c
index 3e5e07e..9bebcd5 100644
--- a/src/plugins/appstream-cache.c
+++ b/src/plugins/appstream-cache.c
@@ -117,6 +117,7 @@ typedef struct {
AppstreamTag tag;
AppstreamImage *image;
AppstreamScreenshot *screenshot;
+ gint priority;
} AppstreamCacheHelper;
/**
@@ -164,6 +165,7 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP:
case APPSTREAM_TAG_KEYWORDS:
case APPSTREAM_TAG_KEYWORD:
+ case APPSTREAM_TAG_PRIORITY:
/* ignore */
break;
case APPSTREAM_TAG_ID:
@@ -268,6 +270,7 @@ appstream_cache_start_element_cb (GMarkupParseContext *context,
return;
}
helper->item_temp = appstream_app_new ();
+ appstream_app_set_priority (helper->item_temp, helper->priority);
appstream_app_set_userdata (helper->item_temp,
(gpointer) helper->path_icons,
NULL);
@@ -381,9 +384,20 @@ appstream_cache_add_item (AppstreamCacheHelper *helper)
id = appstream_app_get_id (helper->item_temp);
item = g_hash_table_lookup (priv->hash_id, id);
if (item != NULL) {
- g_warning ("duplicate AppStream entry: %s", id);
- appstream_app_free (helper->item_temp);
- return;
+
+ /* the previously stored app is higher priority */
+ if (appstream_app_get_priority (item) >
+ appstream_app_get_priority (helper->item_temp)) {
+ g_debug ("ignoring duplicate AppStream entry: %s", id);
+ appstream_app_free (helper->item_temp);
+ return;
+ }
+
+ /* this new item has a higher priority than the one we've
+ * previously stored */
+ g_debug ("replacing duplicate AppStream entry: %s", id);
+ g_hash_table_remove (priv->hash_id, id);
+ g_ptr_array_remove (priv->array, item);
}
/* this is a type we don't know how to handle */
@@ -462,6 +476,9 @@ appstream_cache_end_element_cb (GMarkupParseContext *context,
g_free (helper->lang_temp);
helper->lang_temp = NULL;
break;
+ case APPSTREAM_TAG_PRIORITY:
+ helper->tag = APPSTREAM_TAG_APPLICATIONS;
+ break;
default:
/* ignore unknown entries */
helper->tag = APPSTREAM_TAG_APPLICATION;
@@ -489,6 +506,16 @@ appstream_cache_text_cb (GMarkupParseContext *context,
case APPSTREAM_TAG_KEYWORDS:
/* ignore */
break;
+ case APPSTREAM_TAG_PRIORITY:
+ if (helper->item_temp != NULL) {
+ g_set_error_literal (error,
+ APPSTREAM_CACHE_ERROR,
+ APPSTREAM_CACHE_ERROR_FAILED,
+ "item_temp priority invalid");
+ return;
+ }
+ helper->priority = atoi (text);
+ break;
case APPSTREAM_TAG_APPCATEGORY:
if (helper->item_temp == NULL) {
g_set_error_literal (error,
diff --git a/src/plugins/appstream-common.c b/src/plugins/appstream-common.c
index 4d17114..48a0198 100644
--- a/src/plugins/appstream-common.c
+++ b/src/plugins/appstream-common.c
@@ -72,6 +72,8 @@ appstream_tag_from_string (const gchar *element_name)
return APPSTREAM_TAG_IMAGE;
if (g_strcmp0 (element_name, "compulsory_for_desktop") == 0)
return APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP;
+ if (g_strcmp0 (element_name, "priority") == 0)
+ return APPSTREAM_TAG_PRIORITY;
return APPSTREAM_TAG_UNKNOWN;
}
@@ -121,6 +123,8 @@ appstream_tag_to_string (AppstreamTag tag)
return "image";
if (tag == APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP)
return "compulsory_for_desktop";
+ if (tag == APPSTREAM_TAG_PRIORITY)
+ return "priority";
return NULL;
}
diff --git a/src/plugins/appstream-common.h b/src/plugins/appstream-common.h
index 7f97da8..13b68ac 100644
--- a/src/plugins/appstream-common.h
+++ b/src/plugins/appstream-common.h
@@ -48,6 +48,7 @@ typedef enum {
APPSTREAM_TAG_UPDATECONTACT,
APPSTREAM_TAG_IMAGE,
APPSTREAM_TAG_COMPULSORY_FOR_DESKTOP,
+ APPSTREAM_TAG_PRIORITY,
APPSTREAM_TAG_LAST
} AppstreamTag;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]