mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-02 21:17:47 -04:00
committed by
Atomic Bot
parent
f85416ce55
commit
89a6782c55
@@ -120,6 +120,8 @@ const char * flatpak_get_bwrap (void);
|
||||
|
||||
char *flatpak_get_timezone (void);
|
||||
|
||||
char **flatpak_strv_merge (char **strv1,
|
||||
char **strv2);
|
||||
char **flatpak_subpaths_merge (char **subpaths1,
|
||||
char **subpaths2);
|
||||
|
||||
|
||||
@@ -5690,46 +5690,56 @@ flatpak_format_choices (const char **choices,
|
||||
g_print ("\n");
|
||||
}
|
||||
|
||||
char **
|
||||
flatpak_strv_merge (char **strv1,
|
||||
char **strv2)
|
||||
{
|
||||
GPtrArray *array;
|
||||
int i;
|
||||
|
||||
/* Maybe either (or both) is unspecified */
|
||||
if (strv1 == NULL)
|
||||
return g_strdupv (strv2);
|
||||
if (strv2 == NULL)
|
||||
return g_strdupv (strv1);
|
||||
|
||||
/* Combine both */
|
||||
array = g_ptr_array_new ();
|
||||
|
||||
for (i = 0; strv1[i] != NULL; i++)
|
||||
{
|
||||
if (!flatpak_g_ptr_array_contains_string (array, strv1[i]))
|
||||
g_ptr_array_add (array, g_strdup (strv1[i]));
|
||||
}
|
||||
|
||||
for (i = 0; strv2[i] != NULL; i++)
|
||||
{
|
||||
if (!flatpak_g_ptr_array_contains_string (array, strv2[i]))
|
||||
g_ptr_array_add (array, g_strdup (strv2[i]));
|
||||
}
|
||||
|
||||
g_ptr_array_add (array, NULL);
|
||||
return (char **) g_ptr_array_free (array, FALSE);
|
||||
}
|
||||
|
||||
/* In this NULL means don't care about these paths, while
|
||||
an empty array means match anything */
|
||||
char **
|
||||
flatpak_subpaths_merge (char **subpaths1,
|
||||
char **subpaths2)
|
||||
{
|
||||
GPtrArray *array;
|
||||
int i;
|
||||
char **res;
|
||||
|
||||
/* Maybe either (or both) is unspecified */
|
||||
if (subpaths1 == NULL)
|
||||
return g_strdupv (subpaths2);
|
||||
if (subpaths2 == NULL)
|
||||
if (subpaths1 != NULL && subpaths1[0] == NULL)
|
||||
return g_strdupv (subpaths1);
|
||||
|
||||
/* Check for any "everything" match */
|
||||
if (subpaths1[0] == NULL)
|
||||
return g_strdupv (subpaths1);
|
||||
if (subpaths2[0] == NULL)
|
||||
if (subpaths2 != NULL && subpaths2[0] == NULL)
|
||||
return g_strdupv (subpaths2);
|
||||
|
||||
/* Combine both */
|
||||
array = g_ptr_array_new ();
|
||||
res = flatpak_strv_merge (subpaths1, subpaths2);
|
||||
if (res)
|
||||
qsort (res, g_strv_length (res), sizeof (const char *), flatpak_strcmp0_ptr);
|
||||
|
||||
for (i = 0; subpaths1[i] != NULL; i++)
|
||||
{
|
||||
if (!flatpak_g_ptr_array_contains_string (array, subpaths1[i]))
|
||||
g_ptr_array_add (array, g_strdup (subpaths1[i]));
|
||||
}
|
||||
|
||||
for (i = 0; subpaths2[i] != NULL; i++)
|
||||
{
|
||||
if (!flatpak_g_ptr_array_contains_string (array, subpaths2[i]))
|
||||
g_ptr_array_add (array, g_strdup (subpaths2[i]));
|
||||
}
|
||||
|
||||
g_ptr_array_sort (array, flatpak_strcmp0_ptr);
|
||||
g_ptr_array_add (array, NULL);
|
||||
|
||||
return (char **) g_ptr_array_free (array, FALSE);
|
||||
return res;
|
||||
}
|
||||
|
||||
char *
|
||||
|
||||
@@ -395,11 +395,11 @@ test_subpaths_merge (void)
|
||||
g_auto(GStrv) res = NULL;
|
||||
|
||||
res = flatpak_subpaths_merge (NULL, bla);
|
||||
assert_strv_equal (res, bla);
|
||||
assert_strv_equal (res, bla_sorted);
|
||||
g_clear_pointer (&res, g_strfreev);
|
||||
|
||||
res = flatpak_subpaths_merge (bla, NULL);
|
||||
assert_strv_equal (res, bla);
|
||||
assert_strv_equal (res, bla_sorted);
|
||||
g_clear_pointer (&res, g_strfreev);
|
||||
|
||||
res = flatpak_subpaths_merge (empty, bla);
|
||||
|
||||
Reference in New Issue
Block a user