[gnome-software/wip/temp/ubuntu-xenial-rebased-corrected: 301/331] Properly support multi-line .deb descriptions



commit 3e3e5524cabf0071d5ef63e9f1a886bf31225a00
Author: Richard Hughes <richard hughsie com>
Date:   Sun Apr 24 21:08:20 2016 +0100

    Properly support multi-line .deb descriptions

 data/tests/build-deb.sh          |    1 +
 data/tests/chiron-1.1-1.deb      |  Bin 0 -> 806 bytes
 data/tests/debian/DEBIAN/control |   13 +++++++++++++
 src/gs-self-test.c               |   32 ++++++++++++++++++++++++++++++++
 src/plugins/gs-plugin-dpkg.c     |   19 ++++++++++++++++---
 5 files changed, 62 insertions(+), 3 deletions(-)
---
diff --git a/data/tests/build-deb.sh b/data/tests/build-deb.sh
new file mode 100755
index 0000000..cbf50f6
--- /dev/null
+++ b/data/tests/build-deb.sh
@@ -0,0 +1 @@
+dpkg-deb --build debian chiron-1.1-1.deb
diff --git a/data/tests/chiron-1.1-1.deb b/data/tests/chiron-1.1-1.deb
new file mode 100644
index 0000000..f4f921a
Binary files /dev/null and b/data/tests/chiron-1.1-1.deb differ
diff --git a/data/tests/debian/DEBIAN/control b/data/tests/debian/DEBIAN/control
new file mode 100644
index 0000000..ad5d9c6
--- /dev/null
+++ b/data/tests/debian/DEBIAN/control
@@ -0,0 +1,13 @@
+Package: chiron
+Version: 1.1-1
+Section: base
+Priority: optional
+Architecture: all
+Homepage: http://127.0.0.1/
+Maintainer: Richard Hughes <richard hughsie com>
+Description: Single line synopsis
+ This is the first
+ paragraph in the example package
+ control file.
+ .
+ This is the second paragraph.
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 7a0cb1b..4373239 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -423,6 +423,38 @@ gs_plugin_loader_webapps_func (GsPluginLoader *plugin_loader)
        g_assert (gs_app_get_pixbuf (app) != NULL);
 }
 
+static void
+gs_plugin_loader_dpkg_func (GsPluginLoader *plugin_loader)
+{
+       g_autoptr(GsApp) app = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autofree gchar *fn = NULL;
+
+       /* no dpkg, abort */
+       if (!gs_plugin_loader_get_enabled (plugin_loader, "dpkg"))
+               return;
+
+       /* load local file */
+       fn = gs_test_get_filename ("tests/chiron-1.1-1.deb");
+       g_assert (fn != NULL);
+       app = gs_plugin_loader_filename_to_app (plugin_loader,
+                                               fn,
+                                               GS_PLUGIN_REFINE_FLAGS_DEFAULT,
+                                               NULL,
+                                               &error);
+       g_assert_no_error (error);
+       g_assert (app != NULL);
+       g_assert_cmpstr (gs_app_get_id (app), ==, NULL);
+       g_assert_cmpstr (gs_app_get_source_default (app), ==, "chiron");
+       g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==, "http://127.0.0.1/";);
+       g_assert_cmpstr (gs_app_get_name (app), ==, "chiron");
+       g_assert_cmpstr (gs_app_get_version (app), ==, "1.1-1");
+       g_assert_cmpstr (gs_app_get_summary (app), ==, "Single line synopsis");
+       g_assert_cmpstr (gs_app_get_description (app), ==,
+                        "This is the first paragraph in the example "
+                        "package control file.\nThis is the second paragraph.");
+}
+
 int
 main (int argc, char **argv)
 {
diff --git a/src/plugins/gs-plugin-dpkg.c b/src/plugins/gs-plugin-dpkg.c
index c4945af..e7cc5af 100644
--- a/src/plugins/gs-plugin-dpkg.c
+++ b/src/plugins/gs-plugin-dpkg.c
@@ -61,11 +61,12 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
                           GError **error)
 {
        GsApp *app;
+       guint i;
        g_autofree gchar *content_type = NULL;
-       g_autofree gchar *description = NULL;
        g_autofree gchar *output = NULL;
        g_auto(GStrv) argv = NULL;
        g_auto(GStrv) tokens = NULL;
+       g_autoptr(GString) str = NULL;
        const gchar *mimetypes[] = {
                "application/vnd.debian.binary-package",
                NULL };
@@ -116,8 +117,20 @@ gs_plugin_filename_to_app (GsPlugin *plugin,
        gs_app_set_management_plugin (app, "apt");
 
        /* multiline text */
-       description = g_strjoinv (NULL, tokens + 5);
-       gs_app_set_description (app, GS_APP_QUALITY_LOWEST, description + 1);
+       str = g_string_new ("");
+       for (i = 5; tokens[i] != NULL; i++) {
+               if (g_strcmp0 (tokens[i], " .") == 0) {
+                       if (str->len > 0)
+                               g_string_truncate (str, str->len - 1);
+                       g_string_append (str, "\n");
+                       continue;
+               }
+               g_strstrip (tokens[i]);
+               g_string_append_printf (str, "%s ", tokens[i]);
+       }
+       if (str->len > 0)
+               g_string_truncate (str, str->len - 1);
+       gs_app_set_description (app, GS_APP_QUALITY_LOWEST, str->str);
 
        /* success */
        gs_plugin_add_app (list, app);


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