summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-08-01 09:29:57 +0100
committerRichard Hughes <richard@hughsie.com>2016-08-01 09:49:34 +0100
commit2407c740e0ff94c1e66c5448f971326753baacba (patch)
treeb93a2b4860db09e2c4fa339486d9714002735a81
parent0b60c91524b700d5dcdcccde23af7fc117cbcb9b (diff)
downloadappstream-glib-2407c740e0ff94c1e66c5448f971326753baacba.tar.gz
Include the version in the equality check
-rw-r--r--libappstream-glib/as-app.c52
-rw-r--r--libappstream-glib/as-app.h3
-rw-r--r--libappstream-glib/as-self-test.c14
-rw-r--r--libappstream-glib/as-store.c6
4 files changed, 63 insertions, 12 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 215c230..e0ee3d6 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -102,6 +102,7 @@ typedef struct
gchar *unique_id;
gchar *source_file;
gchar *branch;
+ gchar *version;
gint priority;
gsize token_cache_valid;
GHashTable *token_cache; /* of string:AsAppTokenType* */
@@ -413,6 +414,7 @@ as_app_finalize (GObject *object)
g_free (priv->unique_id);
g_free (priv->source_file);
g_free (priv->branch);
+ g_free (priv->version);
g_hash_table_unref (priv->comments);
g_hash_table_unref (priv->developer_names);
g_hash_table_unref (priv->descriptions);
@@ -549,7 +551,8 @@ as_app_get_bundle_kind (AsApp *app)
* 4. kind, e.g. `app` or `runtime`
* 5. AppStream ID, e.g. `gimp.desktop`
* 6. arch, e.g. `x86_64` or `i386`
- * 7. branch, e.g. `3.20` or `master`
+ * 7. branch, e.g. `stable` or `master`
+ * 8. version, e.g. `3.20.3` or `0.0.1`
*
* Returns: %TRUE if the applications are equal
*
@@ -572,6 +575,8 @@ as_app_equal (AsApp *app1, AsApp *app2)
return FALSE;
if (!as_app_equal_str (priv1->branch, priv2->branch))
return FALSE;
+ if (!as_app_equal_str (priv1->version, priv2->version))
+ return FALSE;
if (!as_app_equal_array_str (priv1->architectures,
priv2->architectures))
return FALSE;
@@ -595,7 +600,7 @@ as_app_fix_unique_nullable (const gchar *tmp)
*
* Gets the unique ID value to represent the component.
*
- * Returns: the unique ID, e.g. "system/package/fedora/desktop/gimp.desktop/i386/master"
+ * Returns: the unique ID, e.g. "system/package/fedora/desktop/gimp.desktop/i386/master/1.2.3"
*
* Since: 0.6.1
**/
@@ -620,14 +625,15 @@ as_app_get_unique_id (AsApp *app)
id_str = as_app_get_id_no_prefix (app);
if (priv->architectures->len == 1)
arch_str = g_ptr_array_index (priv->architectures, 0);
- priv->unique_id = g_strdup_printf ("%s/%s/%s/%s/%s/%s/%s",
+ priv->unique_id = g_strdup_printf ("%s/%s/%s/%s/%s/%s/%s/%s",
as_app_fix_unique_nullable (scope_str),
as_app_fix_unique_nullable (bundle_str),
as_app_fix_unique_nullable (priv->origin),
as_app_fix_unique_nullable (kind_str),
as_app_fix_unique_nullable (id_str),
as_app_fix_unique_nullable (arch_str),
- as_app_fix_unique_nullable (priv->branch));
+ as_app_fix_unique_nullable (priv->branch),
+ as_app_fix_unique_nullable (priv->version));
}
return priv->unique_id;
}
@@ -1842,6 +1848,23 @@ as_app_get_branch (AsApp *app)
return priv->branch;
}
+/**
+ * as_app_get_version:
+ * @app: a #AsApp instance.
+ *
+ * Gets the version for the application.
+ *
+ * Returns: string, or %NULL if unset
+ *
+ * Since: 0.6.1
+ **/
+const gchar *
+as_app_get_version (AsApp *app)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return priv->version;
+}
+
static gboolean
as_app_validate_utf8 (const gchar *text)
{
@@ -2188,6 +2211,23 @@ as_app_set_branch (AsApp *app, const gchar *branch)
}
/**
+ * as_app_set_version:
+ * @app: a #AsApp instance.
+ * @version: the version, e.g. "1.2.3".
+ *
+ * Set the version number of this application.
+ *
+ * Since: 0.6.1
+ **/
+void
+as_app_set_version (AsApp *app, const gchar *version)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ g_free (priv->version);
+ priv->version = g_strdup (version);
+}
+
+/**
* as_app_set_update_contact:
* @app: a #AsApp instance.
* @update_contact: the project license string.
@@ -3450,6 +3490,10 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
if (priv->branch != NULL)
as_app_set_branch (app, priv->branch);
+ /* version */
+ if (priv->version != NULL)
+ as_app_set_version (app, priv->version);
+
/* source_pkgname */
if (priv->source_pkgname != NULL)
as_app_set_source_pkgname (app, priv->source_pkgname);
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index e443cc3..4a47c32 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -351,6 +351,7 @@ const gchar *as_app_get_metadata_license (AsApp *app);
const gchar *as_app_get_update_contact (AsApp *app);
const gchar *as_app_get_source_file (AsApp *app);
const gchar *as_app_get_branch (AsApp *app);
+const gchar *as_app_get_version (AsApp *app);
const gchar *as_app_get_name (AsApp *app,
const gchar *locale);
const gchar *as_app_get_comment (AsApp *app,
@@ -422,6 +423,8 @@ void as_app_set_source_file (AsApp *app,
const gchar *source_file);
void as_app_set_branch (AsApp *app,
const gchar *branch);
+void as_app_set_version (AsApp *app,
+ const gchar *version);
void as_app_set_priority (AsApp *app,
gint priority);
void as_app_add_category (AsApp *app,
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index ab8f7d1..6d86f88 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -1537,7 +1537,7 @@ as_test_app_func (void)
/* verify */
g_assert_cmpstr (as_app_get_id (app), ==, "org.gnome.Software.desktop");
g_assert_cmpstr (as_app_get_id_filename (app), ==, "org.gnome.Software");
- g_assert_cmpstr (as_app_get_unique_id (app), ==, "*/flatpak/*/desktop/org.gnome.Software.desktop/i386/master");
+ g_assert_cmpstr (as_app_get_unique_id (app), ==, "*/flatpak/*/desktop/org.gnome.Software.desktop/i386/master/*");
g_assert_cmpstr (as_app_get_name (app, "pl"), ==, "Oprogramowanie");
g_assert_cmpstr (as_app_get_comment (app, NULL), ==, "Application manager");
g_assert_cmpstr (as_app_get_description (app, NULL), ==, "<p>Software allows you to find stuff</p>");
@@ -2989,19 +2989,19 @@ as_test_store_prefix_func (void)
"flatpak-user:org.gnome.Software.desktop");
/* exact unique match */
- app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/test/*/*",
+ app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/test/*/*/*",
AS_STORE_SEARCH_FLAG_NONE);
g_assert (app_tmp == NULL);
- app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/test/*/*",
+ app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/test/*/*/*",
AS_STORE_SEARCH_FLAG_USE_WILDCARDS);
g_assert (app_tmp == NULL);
- app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/org.gnome.Software.desktop/*/*",
+ app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/org.gnome.Software.desktop/*/*/*",
AS_STORE_SEARCH_FLAG_NONE);
g_assert (app_tmp != NULL);
- app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/org.gnome.Software.desktop/*/*",
+ app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/org.gnome.Software.desktop/*/*/*",
AS_STORE_SEARCH_FLAG_USE_WILDCARDS);
g_assert (app_tmp != NULL);
- app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/*/*/*",
+ app_tmp = as_store_get_app_by_unique_id (store, "*/*/*/*/*/*/*/*",
AS_STORE_SEARCH_FLAG_USE_WILDCARDS);
g_assert (app_tmp != NULL);
}
@@ -3042,7 +3042,7 @@ as_test_store_flatpak_func (void)
g_assert_cmpint (apps->len, ==, 1);
app = g_ptr_array_index (apps, 0);
g_assert_cmpstr (as_app_get_id (app), ==, "flatpak:test.desktop");
- g_assert_cmpstr (as_app_get_unique_id (app), ==, "system/flatpak/remote-name/desktop/test.desktop/x86_64/master");
+ g_assert_cmpstr (as_app_get_unique_id (app), ==, "system/flatpak/remote-name/desktop/test.desktop/x86_64/master/*");
g_assert_cmpstr (as_app_get_id_filename (app), ==, "test");
g_assert_cmpstr (as_app_get_origin (app), ==, "remote-name");
g_assert_cmpstr (as_app_get_source_file (app), ==, filename);
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index 6c8fdb2..82eb15a 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -463,7 +463,7 @@ _as_app_new_from_unique_id (const gchar *unique_id)
g_autoptr(AsApp) app = as_app_new ();
split = g_strsplit (unique_id, "/", -1);
- if (g_strv_length (split) != 7)
+ if (g_strv_length (split) != 8)
return NULL;
if (g_strcmp0 (split[0], AS_APP_UNIQUE_WILDCARD) != 0)
as_app_set_scope (app, as_app_scope_from_string (split[1]));
@@ -489,6 +489,8 @@ _as_app_new_from_unique_id (const gchar *unique_id)
as_app_add_arch (app, split[5]);
if (g_strcmp0 (split[6], AS_APP_UNIQUE_WILDCARD) != 0)
as_app_set_branch (app, split[6]);
+ if (g_strcmp0 (split[7], AS_APP_UNIQUE_WILDCARD) != 0)
+ as_app_set_version (app, split[7]);
return g_steal_pointer (&app);
}
@@ -537,6 +539,8 @@ as_store_get_app_by_unique_id (AsStore *store,
/* create virtual app using scope/system/origin/kind/id/arch/branch */
app_tmp = _as_app_new_from_unique_id (unique_id);
+ if (app_tmp == NULL)
+ return NULL;
return as_store_get_app_by_app (store, app_tmp);
}