diff options
author | Colin Walters <walters@verbum.org> | 2014-07-31 18:50:19 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2014-09-03 13:21:52 -0400 |
commit | f8f5da219edd2279322bba916879fd53c2b65350 (patch) | |
tree | 2bb77d53e3568e70a164112f4b63246737fba45a /src/libotutil/ot-variant-utils.c | |
parent | 3571418557e3a69d5e86dc464499a59df3d38315 (diff) | |
download | ostree-f8f5da219edd2279322bba916879fd53c2b65350.tar.gz |
Add repository "summary" file and metalink support
For Fedora and potentially other distributions which use globally
distributed mirrors, metalink is a popular solution to redirect
clients to a dynamic set of mirrors.
In order to make metalink work though, it needs *one* file which can
be checksummed. (Well, potentially we could explode all refs into the
metalink.xml, but that would be a lot more invasive, and a bit weird
as we'd end up checksumming the checksum file).
This commit adds a new command:
$ ostree summary -u
To regenerate the summary file. Can only be run by one process at a
time.
After that's done, the metalink can be generated based on it, and the
client fetch code will parse and load it.
https://bugzilla.gnome.org/show_bug.cgi?id=729585
Diffstat (limited to 'src/libotutil/ot-variant-utils.c')
-rw-r--r-- | src/libotutil/ot-variant-utils.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/libotutil/ot-variant-utils.c b/src/libotutil/ot-variant-utils.c index ffc2defa..aa3dff56 100644 --- a/src/libotutil/ot-variant-utils.c +++ b/src/libotutil/ot-variant-utils.c @@ -31,6 +31,12 @@ #include "otutil.h" GVariant * +ot_gvariant_new_empty_string_dict (void) +{ + return g_variant_builder_end (g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"))); +} + +GVariant * ot_gvariant_new_bytearray (const guchar *data, gsize len) { @@ -282,3 +288,61 @@ ot_variant_new_from_bytes (const GVariantType *type, (GDestroyNotify)g_bytes_unref, bytes); #endif } + +/** + * ot_variant_bsearch_str: + * @array: A GVariant array whose first element must be a string + * @str: Search for this string + * @out_pos: Output position + * + * + * Binary search in a GVariant array, which must be of the form 'a(s...)', + * where '...' may be anything. The array elements must be sorted. + * + * Returns: %TRUE if found, %FALSE otherwise + */ +gboolean +ot_variant_bsearch_str (GVariant *array, + const char *str, + int *out_pos) +{ + gsize imax, imin; + gsize imid; + gsize n; + + n = g_variant_n_children (array); + if (n == 0) + return FALSE; + + imax = n - 1; + imin = 0; + while (imax >= imin) + { + gs_unref_variant GVariant *child = NULL; + const char *cur; + int cmp; + + imid = (imin + imax) / 2; + + child = g_variant_get_child_value (array, imid); + g_variant_get_child (child, 0, "&s", &cur, NULL); + + cmp = strcmp (cur, str); + if (cmp < 0) + imin = imid + 1; + else if (cmp > 0) + { + if (imid == 0) + break; + imax = imid - 1; + } + else + { + *out_pos = imid; + return TRUE; + } + } + + *out_pos = imid; + return FALSE; +} |