summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-04-23 21:46:24 +0100
committerRichard Hughes <richard@hughsie.com>2008-04-24 09:33:17 +0100
commit5b1f60980c440a73a5498fd22420bfdc7ebc95bb (patch)
tree85e1acb03f75275c7c850bb229db5137bb914a72
parent079e92bfb9cb633535eefbb55f048e598517d769 (diff)
fix pk_va_list_to_argv so that it splits lines with spaces as seporate entries.
This fixes the recent regression where the yum backend could not select updates because the packageid's were being treated as a single entry in the GStrv.
-rw-r--r--libpackagekit/pk-common.c100
1 files changed, 97 insertions, 3 deletions
diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index 6f18f270a..ab36732a9 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -662,11 +662,34 @@ pk_ptr_array_to_argv (GPtrArray *array)
}
/**
+ * pk_va_list_to_argv_string:
+ **/
+static void
+pk_va_list_to_argv_string (GPtrArray *ptr_array, const gchar *string)
+{
+ gchar **array;
+ guint length;
+ guint i;
+
+ /* split the string up by spaces */
+ array = g_strsplit (string, " ", 0);
+
+ /* for each */
+ length = g_strv_length (array);
+ for (i=0; i<length; i++) {
+ g_ptr_array_add (ptr_array, g_strdup (array[i]));
+ }
+ g_strfreev (array);
+}
+
+/**
* pk_va_list_to_argv:
* @string_first: the first string
* @args: any subsequant string's
*
- * Form a composite string array of string
+ * Form a composite string array of string, with a special twist;
+ * if the entry contains a space, then it is split as seporate parts
+ * of the array.
*
* Return value: the string array, or %NULL if invalid
**/
@@ -683,11 +706,16 @@ pk_va_list_to_argv (const gchar *string_first, va_list *args)
/* find how many elements we have in a temp array */
ptr_array = g_ptr_array_new ();
- g_ptr_array_add (ptr_array, g_strdup (string_first));
+ pk_va_list_to_argv_string (ptr_array, string_first);
+
+ /* process all the va_list entries */
for (i=0;; i++) {
value_temp = va_arg (*args, gchar *);
+ /* end of array */
if (value_temp == NULL) break;
- g_ptr_array_add (ptr_array, g_strdup (value_temp));
+
+ /* split the string up by spaces */
+ pk_va_list_to_argv_string (ptr_array, value_temp);
}
pk_debug ("number of strings=%i", i+1);
@@ -768,6 +796,20 @@ pk_strbuild_test (const gchar *first_element, ...)
return text;
}
+static gchar **
+pk_va_list_to_argv_test (const gchar *first_element, ...)
+{
+ va_list args;
+ gchar **array;
+
+ /* get the argument list */
+ va_start (args, first_element);
+ array = pk_va_list_to_argv (first_element, &args);
+ va_end (args);
+
+ return array;
+}
+
void
libst_common (LibSelfTest *test)
{
@@ -861,6 +903,58 @@ libst_common (LibSelfTest *test)
g_free (text_safe);
/************************************************************
+ **************** splitting va_list **************
+ ************************************************************/
+ libst_title (test, "va_list_to_argv single");
+ array = pk_va_list_to_argv_test ("richard", NULL);
+ if (pk_strequal (array[0], "richard") &&
+ array[1] == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "incorrect array '%s'", array[0]);
+ }
+ g_strfreev (array);
+
+ /************************************************************/
+ libst_title (test, "va_list_to_argv triple");
+ array = pk_va_list_to_argv_test ("richard", "phillip", "hughes", NULL);
+ if (pk_strequal (array[0], "richard") &&
+ pk_strequal (array[1], "phillip") &&
+ pk_strequal (array[2], "hughes") &&
+ array[3] == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "incorrect array '%s','%s','%s'", array[0], array[1], array[2]);
+ }
+ g_strfreev (array);
+
+ /************************************************************/
+ libst_title (test, "va_list_to_argv triple with space first");
+ array = pk_va_list_to_argv_test ("richard phillip", "hughes", NULL);
+ if (pk_strequal (array[0], "richard") &&
+ pk_strequal (array[1], "phillip") &&
+ pk_strequal (array[2], "hughes") &&
+ array[3] == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "incorrect array '%s','%s','%s'", array[0], array[1], array[2]);
+ }
+ g_strfreev (array);
+
+ /************************************************************/
+ libst_title (test, "va_list_to_argv triple with space second");
+ array = pk_va_list_to_argv_test ("richard", "phillip hughes", NULL);
+ if (pk_strequal (array[0], "richard") &&
+ pk_strequal (array[1], "phillip") &&
+ pk_strequal (array[2], "hughes") &&
+ array[3] == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "incorrect array '%s','%s','%s'", array[0], array[1], array[2]);
+ }
+ g_strfreev (array);
+
+ /************************************************************
**************** validate text **************
************************************************************/
libst_title (test, "validate correct char 1");