compose: fix mutate-os-release handling

- Let --add-metadata-string=version=val override any automatic version
  prefixing.
- Don't error out if mutate-os-release is given, but no new version is
  given by --add-metadata-string or automatic version prefixing.

Checking keys in parse_keyvalue_strings() is slightly hacky. I initially
wanted to just inspect the GVariantBuilder, but AFAICT, there is no way
to actually look up values from a builder (plus, we need that info early
to know whether automatic_version_prefix should itself inject in the
builder or not).

Closes: #603
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-02-01 11:57:27 -05:00 committed by Atomic Bot
parent 1b7e35abec
commit c756b26521
2 changed files with 18 additions and 22 deletions

View File

@ -518,6 +518,7 @@ process_includes (RpmOstreeTreeComposeContext *self,
static gboolean
parse_keyvalue_strings (char **strings,
GVariantBuilder *builder,
char **out_version,
GError **error)
{
gboolean ret = FALSE;
@ -538,8 +539,15 @@ parse_keyvalue_strings (char **strings,
"Missing '=' in KEY=VALUE metadata '%s'", s);
goto out;
}
key = g_strndup (s, eq - s);
if (g_str_equal (key, "version"))
{
g_free (*out_version);
*out_version = g_strdup (eq + 1);
}
g_variant_builder_add (builder, "{sv}", key,
g_variant_new_string (eq + 1));
}
@ -549,23 +557,6 @@ parse_keyvalue_strings (char **strings,
return ret;
}
static gboolean
compose_strv_contains_prefix (gchar **strv,
const gchar *prefix)
{
if (!strv)
return FALSE;
while (*strv)
{
if (g_str_has_prefix (*strv, prefix))
return TRUE;
++strv;
}
return FALSE;
}
static gboolean
process_touch_if_changed (GError **error)
{
@ -706,8 +697,8 @@ rpmostree_compose_builtin_tree (int argc,
if (opt_metadata_strings)
{
if (!parse_keyvalue_strings (opt_metadata_strings,
metadata_builder, error))
if (!parse_keyvalue_strings (opt_metadata_strings, metadata_builder,
&next_version, error))
goto out;
}
@ -795,7 +786,8 @@ rpmostree_compose_builtin_tree (int argc,
goto out;
if (json_object_has_member (treefile, "automatic_version_prefix") &&
!compose_strv_contains_prefix (opt_metadata_strings, "version="))
/* let --add-metadata-string=version=... take precedence */
(next_version == NULL))
{
g_autoptr(GVariant) variant = NULL;
g_autofree char *last_version = NULL;

View File

@ -1485,7 +1485,11 @@ rpmostree_treefile_postprocessing (int rootfs_fd,
error))
goto out;
if (base_version != NULL)
if (base_version != NULL && next_version == NULL)
{
g_print ("Ignoring mutate-os-release: no commit version specified.");
}
else if (base_version != NULL)
{
g_autofree char *contents = NULL;
g_autofree char *new_contents = NULL;