[gnome-software/wip/ubuntu-xenial] Properly support multi-line .deb descriptions



commit 734c83de2859f1df5b339d54245505ffc3068523
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               |   52 ++++++++++++++++++++++++++++++++++++-
 src/plugins/gs-plugin-dpkg.c     |   19 +++++++++++--
 5 files changed, 80 insertions(+), 5 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 443dc78..22dcfbb 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -23,7 +23,6 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <gtk/gtk.h>
 #include <glib/gstdio.h>
 
 #include "gs-app.h"
@@ -679,10 +678,58 @@ gs_plugin_loader_webapps_func (void)
        g_unlink (path);
 }
 
+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)
 {
-       gtk_init (&argc, &argv);
+       gboolean ret;
+       g_autofree gchar *fn = NULL;
+       g_autofree gchar *xml = NULL;
+       g_autoptr(GError) error = NULL;
+       g_autoptr(GsPluginLoader) plugin_loader = NULL;
+       const gchar *whitelist[] = {
+               "appstream",
+               "dpkg",
+               "dummy",
+               "epiphany",
+               "hardcoded-blacklist",
+               "icons",
+               "menu-spec-refine",
+               "provenance",
+               NULL
+       };
+
        g_test_init (&argc, &argv, NULL);
        g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
        g_setenv ("GNOME_SOFTWARE_SELF_TEST", "1", TRUE);
@@ -701,6 +748,7 @@ main (int argc, char **argv)
        g_test_add_func ("/gnome-software/plugin-loader{dedupe}", gs_plugin_loader_dedupe_func);
        if(0)g_test_add_func ("/gnome-software/plugin-loader", gs_plugin_loader_func);
        if(0)g_test_add_func ("/gnome-software/plugin-loader{webapps}", gs_plugin_loader_webapps_func);
+       if(0)g_test_add_func ("/gnome-software/plugin-loader{dpkg}", gs_plugin_loader_dpkg_func);
 
        return g_test_run ();
 }
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]