summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-07-29 19:00:45 +0100
committerRichard Hughes <richard@hughsie.com>2014-07-29 19:00:45 +0100
commitda7933b0fdae3d511d79353d3f35775f7318364c (patch)
tree62b1b4cbe44cfd94eace9aaaeea183375b08173d
parent6c9c5a8c67c309cae758288631b02663fccf91ca (diff)
downloadappstream-glib-da7933b0fdae3d511d79353d3f35775f7318364c.tar.gz
Add support for <source_pkgname> which will be in AppStream 0.8
-rw-r--r--libappstream-builder/asb-package-rpm.c9
-rw-r--r--libappstream-builder/asb-package.c51
-rw-r--r--libappstream-builder/asb-package.h3
-rw-r--r--libappstream-builder/asb-task.c9
-rw-r--r--libappstream-glib/as-app.c59
-rw-r--r--libappstream-glib/as-app.h4
-rw-r--r--libappstream-glib/as-self-test.c2
-rw-r--r--libappstream-glib/as-tag.c1
-rw-r--r--libappstream-glib/as-tag.gperf1
-rw-r--r--libappstream-glib/as-tag.h2
10 files changed, 134 insertions, 7 deletions
diff --git a/libappstream-builder/asb-package-rpm.c b/libappstream-builder/asb-package-rpm.c
index f54c370..0deeb2b 100644
--- a/libappstream-builder/asb-package-rpm.c
+++ b/libappstream-builder/asb-package-rpm.c
@@ -227,6 +227,15 @@ asb_package_rpm_set_source (AsbPackage *pkg, const gchar *source)
if (tmp != NULL)
*tmp = '\0';
asb_package_set_source (pkg, srcrpm);
+
+ /* get the srpm name */
+ tmp = g_strrstr (srcrpm, "-");
+ if (tmp != NULL)
+ *tmp = '\0';
+ tmp = g_strrstr (srcrpm, "-");
+ if (tmp != NULL)
+ *tmp = '\0';
+ asb_package_set_source_pkgname (pkg, srcrpm);
}
/**
diff --git a/libappstream-builder/asb-package.c b/libappstream-builder/asb-package.c
index f58aafa..ed4c826 100644
--- a/libappstream-builder/asb-package.c
+++ b/libappstream-builder/asb-package.c
@@ -52,7 +52,8 @@ struct _AsbPackagePrivate
gchar *nevr;
gchar *evr;
gchar *license;
- gchar *source;
+ gchar *source_nevra;
+ gchar *source_pkgname;
GString *log;
GHashTable *configs;
GTimer *timer;
@@ -86,7 +87,8 @@ asb_package_finalize (GObject *object)
g_free (priv->nevr);
g_free (priv->evr);
g_free (priv->license);
- g_free (priv->source);
+ g_free (priv->source_nevra);
+ g_free (priv->source_pkgname);
g_string_free (priv->log, TRUE);
g_timer_destroy (priv->timer);
g_hash_table_unref (priv->configs);
@@ -326,7 +328,7 @@ asb_package_get_license (AsbPackage *pkg)
* asb_package_get_source:
* @pkg: A #AsbPackage
*
- * Gets the package source name.
+ * Gets the package source nevra.
*
* Returns: utf8 string
*
@@ -336,7 +338,24 @@ const gchar *
asb_package_get_source (AsbPackage *pkg)
{
AsbPackagePrivate *priv = GET_PRIVATE (pkg);
- return priv->source;
+ return priv->source_nevra;
+}
+
+/**
+ * asb_package_get_source_pkgname:
+ * @pkg: A #AsbPackage
+ *
+ * Gets the package source name.
+ *
+ * Returns: utf8 string
+ *
+ * Since: 0.2.4
+ **/
+const gchar *
+asb_package_get_source_pkgname (AsbPackage *pkg)
+{
+ AsbPackagePrivate *priv = GET_PRIVATE (pkg);
+ return priv->source_pkgname;
}
/**
@@ -494,7 +513,7 @@ asb_package_set_license (AsbPackage *pkg, const gchar *license)
/**
* asb_package_set_source:
* @pkg: A #AsbPackage
- * @source: source string, e.g. the srpm name
+ * @source: source string, e.g. the srpm nevra
*
* Sets the package source name, which is usually the parent of a set of
* subpackages.
@@ -505,8 +524,26 @@ void
asb_package_set_source (AsbPackage *pkg, const gchar *source)
{
AsbPackagePrivate *priv = GET_PRIVATE (pkg);
- g_free (priv->source);
- priv->source = g_strdup (source);
+ g_free (priv->source_nevra);
+ priv->source_nevra = g_strdup (source);
+}
+
+/**
+ * asb_package_set_source_pkgname:
+ * @pkg: A #AsbPackage
+ * @source_pkgname: source string, e.g. the srpm name
+ *
+ * Sets the package source name, which is usually the parent of a set of
+ * subpackages.
+ *
+ * Since: 0.2.4
+ **/
+void
+asb_package_set_source_pkgname (AsbPackage *pkg, const gchar *source_pkgname)
+{
+ AsbPackagePrivate *priv = GET_PRIVATE (pkg);
+ g_free (priv->source_pkgname);
+ priv->source_pkgname = g_strdup (source_pkgname);
}
/**
diff --git a/libappstream-builder/asb-package.h b/libappstream-builder/asb-package.h
index 55cf644..6683299 100644
--- a/libappstream-builder/asb-package.h
+++ b/libappstream-builder/asb-package.h
@@ -91,6 +91,7 @@ const gchar *asb_package_get_evr (AsbPackage *pkg);
const gchar *asb_package_get_url (AsbPackage *pkg);
const gchar *asb_package_get_license (AsbPackage *pkg);
const gchar *asb_package_get_source (AsbPackage *pkg);
+const gchar *asb_package_get_source_pkgname (AsbPackage *pkg);
void asb_package_set_name (AsbPackage *pkg,
const gchar *name);
void asb_package_set_version (AsbPackage *pkg,
@@ -107,6 +108,8 @@ void asb_package_set_license (AsbPackage *pkg,
const gchar *license);
void asb_package_set_source (AsbPackage *pkg,
const gchar *source);
+void asb_package_set_source_pkgname (AsbPackage *pkg,
+ const gchar *source_pkgname);
void asb_package_set_deps (AsbPackage *pkg,
gchar **deps);
void asb_package_set_filelist (AsbPackage *pkg,
diff --git a/libappstream-builder/asb-task.c b/libappstream-builder/asb-task.c
index e6e8708..e579781 100644
--- a/libappstream-builder/asb-task.c
+++ b/libappstream-builder/asb-task.c
@@ -399,6 +399,15 @@ asb_task_process (AsbTask *task, GError **error_not_used)
asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_NONE, "%s", tmp);
g_free (tmp);
}
+
+ /* add the source name so we can suggest these together */
+ if (nr_added > 1) {
+ for (l = apps; l != NULL; l = l->next) {
+ as_app_set_source_pkgname (AS_APP (l->data),
+ asb_package_get_source_pkgname (priv->pkg),
+ -1);
+ }
+ }
skip:
/* add a dummy element to the AppStream metadata so that we don't keep
* parsing this every time */
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index e58b544..546c04d 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -82,6 +82,7 @@ struct _AsAppPrivate
gchar *project_group;
gchar *project_license;
gchar *metadata_license;
+ gchar *source_pkgname;
gchar *update_contact;
gchar *source_file;
gint priority;
@@ -243,6 +244,7 @@ as_app_finalize (GObject *object)
g_free (priv->project_group);
g_free (priv->project_license);
g_free (priv->metadata_license);
+ g_free (priv->source_pkgname);
g_free (priv->update_contact);
g_free (priv->source_file);
g_hash_table_unref (priv->comments);
@@ -932,6 +934,25 @@ as_app_get_pkgname_default (AsApp *app)
}
/**
+ * as_app_get_source_pkgname:
+ * @app: a #AsApp instance.
+ *
+ * Gets the source package name that produced the binary package.
+ * Only source packages producing more than one binary package will have this
+ * entry set.
+ *
+ * Returns: string, or %NULL if unset
+ *
+ * Since: 0.2.4
+ **/
+const gchar *
+as_app_get_source_pkgname (AsApp *app)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return priv->source_pkgname;
+}
+
+/**
* as_app_get_icon_path:
* @app: a #AsApp instance.
*
@@ -1463,6 +1484,33 @@ as_app_set_metadata_license (AsApp *app,
}
/**
+ * as_app_set_source_pkgname:
+ * @app: a #AsApp instance.
+ * @source_pkgname: the project license string.
+ * @source_pkgname_len: the size of @source_pkgname, or -1 if %NULL-terminated.
+ *
+ * Set the project license.
+ *
+ * Since: 0.2.4
+ **/
+void
+as_app_set_source_pkgname (AsApp *app,
+ const gchar *source_pkgname,
+ gssize source_pkgname_len)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+
+ /* handle untrusted */
+ if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_VALID_UTF8) > 0 &&
+ !as_app_validate_utf8 (source_pkgname, source_pkgname_len)) {
+ priv->problems |= AS_APP_PROBLEM_NOT_VALID_UTF8;
+ return;
+ }
+ g_free (priv->source_pkgname);
+ priv->source_pkgname = as_strndup (source_pkgname, source_pkgname_len);
+}
+
+/**
* as_app_set_source_file:
* @app: a #AsApp instance.
* @source_file: the filename.
@@ -2667,6 +2715,12 @@ as_app_node_insert (AsApp *app, GNode *parent, gdouble api_version)
}
}
+ /* <source_pkgname> */
+ if (priv->source_pkgname != NULL && api_version >= 0.8) {
+ as_node_insert (node_app, "source_pkgname",
+ priv->source_pkgname, 0, NULL);
+ }
+
/* <url> */
as_node_insert_hash (node_app, "url", "type", priv->urls, 0);
@@ -2933,6 +2987,11 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags, GError **e
as_app_set_metadata_license (app, as_node_get_data (n), -1);
break;
+ /* <source_pkgname> */
+ case AS_TAG_SOURCE_PKGNAME:
+ as_app_set_source_pkgname (app, as_node_get_data (n), -1);
+ break;
+
/* <updatecontact> */
case AS_TAG_UPDATE_CONTACT:
as_app_set_update_contact (app, as_node_get_data (n), -1);
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index d020f78..0b9e882 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -237,6 +237,7 @@ const gchar *as_app_get_icon_path (AsApp *app);
const gchar *as_app_get_id (AsApp *app);
const gchar *as_app_get_id_full (AsApp *app);
const gchar *as_app_get_pkgname_default (AsApp *app);
+const gchar *as_app_get_source_pkgname (AsApp *app);
const gchar *as_app_get_project_group (AsApp *app);
const gchar *as_app_get_project_license (AsApp *app);
const gchar *as_app_get_metadata_license (AsApp *app);
@@ -285,6 +286,9 @@ void as_app_set_project_license (AsApp *app,
void as_app_set_metadata_license (AsApp *app,
const gchar *metadata_license,
gssize metadata_license_len);
+void as_app_set_source_pkgname (AsApp *app,
+ const gchar *source_pkgname,
+ gssize source_pkgname_len);
void as_app_set_update_contact (AsApp *app,
const gchar *update_contact,
gssize update_contact_len);
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 170228a..afb48a0 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -543,6 +543,7 @@ as_test_app_func (void)
"<mimetype>application/vnd.oasis.opendocument.spreadsheet</mimetype>"
"</mimetypes>"
"<project_license>GPLv2+</project_license>"
+ "<source_pkgname>gnome-software-src</source_pkgname>"
"<url type=\"homepage\">https://wiki.gnome.org/Design/Apps/Software</url>"
"<project_group>GNOME</project_group>"
"<compulsory_for_desktop>GNOME</compulsory_for_desktop>"
@@ -591,6 +592,7 @@ as_test_app_func (void)
g_assert_cmpstr (as_app_get_comment (app, NULL), ==, "Application manager");
g_assert_cmpstr (as_app_get_developer_name (app, NULL), ==, "GNOME Foundation");
g_assert_cmpstr (as_app_get_icon (app), ==, "org.gnome.Software.png");
+ g_assert_cmpstr (as_app_get_source_pkgname (app), ==, "gnome-software-src");
g_assert_cmpint (as_app_get_icon_kind (app), ==, AS_ICON_KIND_CACHED);
g_assert_cmpint (as_app_get_source_kind (app), ==, AS_APP_SOURCE_KIND_UNKNOWN);
g_assert_cmpstr (as_app_get_project_group (app), ==, "GNOME");
diff --git a/libappstream-glib/as-tag.c b/libappstream-glib/as-tag.c
index 0082258..ccbb293 100644
--- a/libappstream-glib/as-tag.c
+++ b/libappstream-glib/as-tag.c
@@ -172,6 +172,7 @@ as_tag_to_string (AsTag tag)
"developer_name",
"kudos",
"kudo",
+ "source_pkgname",
NULL };
if (tag > AS_TAG_LAST)
tag = AS_TAG_LAST;
diff --git a/libappstream-glib/as-tag.gperf b/libappstream-glib/as-tag.gperf
index 877bd88..35282c9 100644
--- a/libappstream-glib/as-tag.gperf
+++ b/libappstream-glib/as-tag.gperf
@@ -46,3 +46,4 @@ extends, AS_TAG_EXTENDS
developer_name, AS_TAG_DEVELOPER_NAME
kudos, AS_TAG_KUDOS
kudo, AS_TAG_KUDO
+source_pkgname, AS_TAG_SOURCE_PKGNAME
diff --git a/libappstream-glib/as-tag.h b/libappstream-glib/as-tag.h
index cb9f3bd..02656d6 100644
--- a/libappstream-glib/as-tag.h
+++ b/libappstream-glib/as-tag.h
@@ -69,6 +69,7 @@
* @AS_TAG_DEVELOPER_NAME: `developer_name`
* @AS_TAG_KUDOS: `kudos`
* @AS_TAG_KUDO: `kudo`
+ * @AS_TAG_SOURCE_PKGNAME: `source_pkgname`
*
* The tag type.
**/
@@ -112,6 +113,7 @@ typedef enum {
AS_TAG_DEVELOPER_NAME, /* Since: 0.1.8 */
AS_TAG_KUDOS, /* Since: 0.2.1 */
AS_TAG_KUDO, /* Since: 0.2.1 */
+ AS_TAG_SOURCE_PKGNAME, /* Since: 0.2.4 */
/*< private >*/
AS_TAG_LAST
} AsTag;