summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-08-05 21:28:00 +0100
committerRichard Hughes <richard@hughsie.com>2016-08-05 21:28:09 +0100
commit628ffa095316b5afc8a57bd3092b63dcf4d3a285 (patch)
tree25f085a159f72a0133796d24276e3c90c5e2a19d
parent154772a71a0fadafc4416356bf8c1391405f4bd2 (diff)
downloadappstream-glib-628ffa095316b5afc8a57bd3092b63dcf4d3a285.tar.gz
Only subsume a safe subset from merge components
We certainly don't want to copy over the source file, origin, branch or version from the merged application.
-rw-r--r--libappstream-glib/as-app.c163
-rw-r--r--libappstream-glib/as-app.h10
-rw-r--r--libappstream-glib/as-self-test.c5
-rw-r--r--libappstream-glib/as-store.c6
4 files changed, 100 insertions, 84 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index d1c14d9..d5897ff 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -3350,58 +3350,23 @@ as_app_subsume_icon (AsApp *app, AsIcon *icon)
}
static void
-as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
+as_app_subsume_merge (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
{
- AsAppPrivate *priv = GET_PRIVATE (donor);
AsAppPrivate *papp = GET_PRIVATE (app);
- AsBundle *bundle;
- AsTranslation *translation;
- AsReview *review;
- AsScreenshot *ss;
- AsProvide *pr;
- const gchar *tmp;
- const gchar *key;
+ AsAppPrivate *priv = GET_PRIVATE (donor);
gboolean overwrite;
guint i;
- gint percentage;
- GList *l;
- g_autoptr(GList) keys = NULL;
-
- /* stop us shooting ourselves in the foot */
- papp->trust_flags |= AS_APP_TRUST_FLAG_CHECK_DUPLICATES;
-
- overwrite = (flags & AS_APP_SUBSUME_FLAG_NO_OVERWRITE) == 0;
-
- /* id-kind */
- if (papp->kind == AS_APP_KIND_UNKNOWN)
- as_app_set_kind (app, priv->kind);
-
- /* AppData or AppStream can overwrite the id-kind of desktop files */
- if ((priv->source_kind == AS_APP_SOURCE_KIND_APPDATA ||
- priv->source_kind == AS_APP_SOURCE_KIND_APPSTREAM) &&
- papp->source_kind == AS_APP_SOURCE_KIND_DESKTOP)
- as_app_set_kind (app, priv->kind);
-
- /* state */
- if (papp->state == AS_APP_STATE_UNKNOWN)
- as_app_set_state (app, priv->state);
-
- /* pkgnames */
- for (i = 0; i < priv->pkgnames->len; i++) {
- tmp = g_ptr_array_index (priv->pkgnames, i);
- as_app_add_pkgname (app, tmp);
- }
- /* bundles */
- for (i = 0; i < priv->bundles->len; i++) {
- bundle = g_ptr_array_index (priv->bundles, i);
- as_app_add_bundle (app, bundle);
+ /* categories */
+ for (i = 0; i < priv->categories->len; i++) {
+ const gchar *tmp = g_ptr_array_index (priv->categories, i);
+ as_app_add_category (app, tmp);
}
/* translations */
for (i = 0; i < priv->translations->len; i++) {
- translation = g_ptr_array_index (priv->translations, i);
- as_app_add_translation (app, translation);
+ AsTranslation *tr = g_ptr_array_index (priv->translations, i);
+ as_app_add_translation (app, tr);
}
/* releases */
@@ -3412,56 +3377,49 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
/* kudos */
for (i = 0; i < priv->kudos->len; i++) {
- tmp = g_ptr_array_index (priv->kudos, i);
+ const gchar *tmp = g_ptr_array_index (priv->kudos, i);
as_app_add_kudo (app, tmp);
}
- /* categories */
- for (i = 0; i < priv->categories->len; i++) {
- tmp = g_ptr_array_index (priv->categories, i);
- as_app_add_category (app, tmp);
- }
-
/* permissions */
for (i = 0; i < priv->permissions->len; i++) {
- tmp = g_ptr_array_index (priv->permissions, i);
+ const gchar *tmp = g_ptr_array_index (priv->permissions, i);
as_app_add_permission (app, tmp);
}
/* extends */
for (i = 0; i < priv->extends->len; i++) {
- tmp = g_ptr_array_index (priv->extends, i);
+ const gchar *tmp = g_ptr_array_index (priv->extends, i);
as_app_add_extends (app, tmp);
}
/* compulsory_for_desktops */
for (i = 0; i < priv->compulsory_for_desktops->len; i++) {
- tmp = g_ptr_array_index (priv->compulsory_for_desktops, i);
+ const gchar *tmp = g_ptr_array_index (priv->compulsory_for_desktops, i);
as_app_add_compulsory_for_desktop (app, tmp);
}
/* screenshots */
for (i = 0; i < priv->screenshots->len; i++) {
- ss = g_ptr_array_index (priv->screenshots, i);
+ AsScreenshot *ss = g_ptr_array_index (priv->screenshots, i);
as_app_add_screenshot (app, ss);
}
/* reviews */
for (i = 0; i < priv->reviews->len; i++) {
- review = g_ptr_array_index (priv->reviews, i);
+ AsReview *review = g_ptr_array_index (priv->reviews, i);
as_app_add_review (app, review);
}
/* content_ratings */
for (i = 0; i < priv->content_ratings->len; i++) {
- AsContentRating *content_rating;
- content_rating = g_ptr_array_index (priv->content_ratings, i);
- as_app_add_content_rating (app, content_rating);
+ AsContentRating *cr = g_ptr_array_index (priv->content_ratings, i);
+ as_app_add_content_rating (app, cr);
}
/* provides */
for (i = 0; i < priv->provides->len; i++) {
- pr = g_ptr_array_index (priv->provides, i);
+ AsProvide *pr = g_ptr_array_index (priv->provides, i);
as_app_add_provide (app, pr);
}
@@ -3473,20 +3431,82 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
/* mimetypes */
for (i = 0; i < priv->mimetypes->len; i++) {
- tmp = g_ptr_array_index (priv->mimetypes, i);
+ const gchar *tmp = g_ptr_array_index (priv->mimetypes, i);
as_app_add_mimetype (app, tmp);
}
- /* do not subsume all properties */
- if ((flags & AS_APP_SUBSUME_FLAG_PARTIAL) > 0)
- return;
-
/* vetos */
for (i = 0; i < priv->vetos->len; i++) {
- tmp = g_ptr_array_index (priv->vetos, i);
+ const gchar *tmp = g_ptr_array_index (priv->vetos, i);
as_app_add_veto (app, "%s", tmp);
}
+ /* dictionaries */
+ overwrite = (flags & AS_APP_SUBSUME_FLAG_NO_OVERWRITE) == 0;
+ as_app_subsume_dict (papp->names, priv->names, overwrite);
+ as_app_subsume_dict (papp->comments, priv->comments, overwrite);
+ as_app_subsume_dict (papp->developer_names, priv->developer_names, overwrite);
+ as_app_subsume_dict (papp->descriptions, priv->descriptions, overwrite);
+ as_app_subsume_dict (papp->metadata, priv->metadata, overwrite);
+ as_app_subsume_dict (papp->urls, priv->urls, overwrite);
+ as_app_subsume_keywords (app, donor, overwrite);
+
+ /* project_group */
+ if (priv->project_group != NULL)
+ as_app_set_project_group (app, priv->project_group);
+}
+
+static void
+as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
+{
+ AsAppPrivate *priv = GET_PRIVATE (donor);
+ AsAppPrivate *papp = GET_PRIVATE (app);
+ AsBundle *bundle;
+ const gchar *tmp;
+ const gchar *key;
+ guint i;
+ gint percentage;
+ GList *l;
+ g_autoptr(GList) keys = NULL;
+
+ /* stop us shooting ourselves in the foot */
+ papp->trust_flags |= AS_APP_TRUST_FLAG_CHECK_DUPLICATES;
+
+ /* safe things that can be done from merge components */
+ as_app_subsume_merge (app, donor, flags);
+ if (flags & AS_APP_SUBSUME_FLAG_ONLY_MERGE)
+ return;
+
+ /* id-kind */
+ if (papp->kind == AS_APP_KIND_UNKNOWN)
+ as_app_set_kind (app, priv->kind);
+
+ /* AppData or AppStream can overwrite the id-kind of desktop files */
+ if ((priv->source_kind == AS_APP_SOURCE_KIND_APPDATA ||
+ priv->source_kind == AS_APP_SOURCE_KIND_APPSTREAM) &&
+ papp->source_kind == AS_APP_SOURCE_KIND_DESKTOP)
+ as_app_set_kind (app, priv->kind);
+
+ /* state */
+ if (papp->state == AS_APP_STATE_UNKNOWN)
+ as_app_set_state (app, priv->state);
+
+ /* pkgnames */
+ for (i = 0; i < priv->pkgnames->len; i++) {
+ tmp = g_ptr_array_index (priv->pkgnames, i);
+ as_app_add_pkgname (app, tmp);
+ }
+
+ /* bundles */
+ for (i = 0; i < priv->bundles->len; i++) {
+ bundle = g_ptr_array_index (priv->bundles, i);
+ as_app_add_bundle (app, bundle);
+ }
+
+ /* do not subsume all properties */
+ if ((flags & AS_APP_SUBSUME_FLAG_PARTIAL) > 0)
+ return;
+
/* languages */
keys = g_hash_table_get_keys (priv->languages);
for (l = keys; l != NULL; l = l->next) {
@@ -3500,15 +3520,6 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
as_app_add_language (app, percentage, key);
}
- /* dictionaries */
- as_app_subsume_dict (papp->names, priv->names, overwrite);
- as_app_subsume_dict (papp->comments, priv->comments, overwrite);
- as_app_subsume_dict (papp->developer_names, priv->developer_names, overwrite);
- as_app_subsume_dict (papp->descriptions, priv->descriptions, overwrite);
- as_app_subsume_dict (papp->metadata, priv->metadata, overwrite);
- as_app_subsume_dict (papp->urls, priv->urls, overwrite);
- as_app_subsume_keywords (app, donor, overwrite);
-
/* source */
if (priv->source_file != NULL)
as_app_set_source_file (app, priv->source_file);
@@ -3534,10 +3545,6 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
as_app_set_project_license (app, priv->project_license);
if (priv->metadata_license != NULL)
as_app_set_metadata_license (app, priv->metadata_license);
-
- /* project_group */
- if (priv->project_group != NULL)
- as_app_set_project_group (app, priv->project_group);
}
/**
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index 4a47c32..f9c6f90 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -89,14 +89,16 @@ typedef enum {
* @AS_APP_SUBSUME_FLAG_NO_OVERWRITE: Do not overwrite already set properties
* @AS_APP_SUBSUME_FLAG_BOTH_WAYS: Copy unset properties both ways
* @AS_APP_SUBSUME_FLAG_PARTIAL: Only subsume a safe subset
+ * @AS_APP_SUBSUME_FLAG_ONLY_MERGE: Only copy properties allowed in merge components
*
* The flags to use when subsuming applications.
**/
typedef enum {
- AS_APP_SUBSUME_FLAG_NONE,
- AS_APP_SUBSUME_FLAG_NO_OVERWRITE = 1, /* Since: 0.1.4 */
- AS_APP_SUBSUME_FLAG_BOTH_WAYS = 2, /* Since: 0.1.4 */
- AS_APP_SUBSUME_FLAG_PARTIAL = 4, /* Since: 0.2.2 */
+ AS_APP_SUBSUME_FLAG_NONE = 0,
+ AS_APP_SUBSUME_FLAG_NO_OVERWRITE = 1 << 0, /* Since: 0.1.4 */
+ AS_APP_SUBSUME_FLAG_BOTH_WAYS = 1 << 1, /* Since: 0.1.4 */
+ AS_APP_SUBSUME_FLAG_PARTIAL = 1 << 2, /* Since: 0.2.2 */
+ AS_APP_SUBSUME_FLAG_ONLY_MERGE = 1 << 3, /* Since: 0.6.1 */
/*< private >*/
AS_APP_SUBSUME_FLAG_LAST,
} AsAppSubsumeFlags;
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 1007fd6..6729b24 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -5105,6 +5105,7 @@ as_test_store_merge_func (void)
as_app_set_origin (app_merge, "utopia");
as_app_set_scope (app_merge, AS_APP_SCOPE_USER);
as_app_add_category (app_merge, "special");
+ as_app_set_source_file (app_merge, "DO-NOT-SUBSUME.xml");
as_store_add_app (store, app_merge);
g_assert_cmpstr (as_app_get_unique_id (app_merge), ==,
"*/*/*/desktop/org.gnome.Software.desktop/*/*/*");
@@ -5122,6 +5123,10 @@ as_test_store_merge_func (void)
/* verify that both apps have the category */
g_assert (as_app_has_category (app1, "special"));
g_assert (as_app_has_category (app2, "special"));
+
+ /* verify we didn't inherit the private bits */
+ g_assert_cmpstr (as_app_get_source_file (app1), ==, NULL);
+ g_assert_cmpstr (as_app_get_source_file (app2), ==, NULL);
}
int
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 75ac88c..7a87bd1 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -953,7 +953,8 @@ as_store_add_app (AsStore *store, AsApp *app)
g_debug ("using merge component %s on %s",
id, as_app_get_unique_id (app_tmp));
as_app_subsume_full (app_tmp, app,
- AS_APP_SUBSUME_FLAG_NO_OVERWRITE);
+ AS_APP_SUBSUME_FLAG_NO_OVERWRITE |
+ AS_APP_SUBSUME_FLAG_ONLY_MERGE);
}
return;
}
@@ -967,7 +968,8 @@ as_store_add_app (AsStore *store, AsApp *app)
as_app_get_unique_id (app_tmp),
as_app_get_unique_id (app));
as_app_subsume_full (app, app_tmp,
- AS_APP_SUBSUME_FLAG_NO_OVERWRITE);
+ AS_APP_SUBSUME_FLAG_NO_OVERWRITE |
+ AS_APP_SUBSUME_FLAG_ONLY_MERGE);
}
}