app/composeutil: Refactor reading JSON metadata from file
Instead of relying on `rpmostree_composeutil_read_json_metadata` to initialize the metadata hash table, initialize it explicitly in `context_new()` function and only call the util function if we were passed a file with `--add-metadata-from-json`. Accordingly rename the function `rpmostree_composeutil_read_json_metadata_from_file`. Closes: #1865 Approved by: cgwalters
This commit is contained in:
parent
c94bd08b02
commit
40bb310e97
@ -276,9 +276,14 @@ rpm_ostree_rojig_compose_new (const char *treefile_path,
|
||||
if (!self->repo)
|
||||
return glnx_prefix_error (error, "Creating repo-build");
|
||||
|
||||
self->metadata = rpmostree_composeutil_read_json_metadata (opt_metadata_json, error);
|
||||
if (!self->metadata)
|
||||
self->metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
|
||||
(GDestroyNotify)g_variant_unref);
|
||||
if (opt_metadata_json)
|
||||
{
|
||||
if (!rpmostree_composeutil_read_json_metadata_from_file (opt_metadata_json,
|
||||
self->metadata, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
self->corectx = rpmostree_context_new_tree (self->cachedir_dfd, self->repo, cancellable, error);
|
||||
if (!self->corectx)
|
||||
|
@ -682,9 +682,14 @@ rpm_ostree_compose_context_new (const char *treefile_pathstr,
|
||||
|
||||
self->treefile_path = g_file_new_for_path (treefile_pathstr);
|
||||
|
||||
self->metadata = rpmostree_composeutil_read_json_metadata (opt_metadata_json, error);
|
||||
if (!self->metadata)
|
||||
self->metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
|
||||
(GDestroyNotify)g_variant_unref);
|
||||
if (opt_metadata_json)
|
||||
{
|
||||
if (!rpmostree_composeutil_read_json_metadata_from_file (opt_metadata_json,
|
||||
self->metadata, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (opt_metadata_strings)
|
||||
{
|
||||
|
@ -320,13 +320,13 @@ rpmostree_composeutil_get_treespec (RpmOstreeContext *ctx,
|
||||
/* compose tree accepts JSON metadata via file; convert it
|
||||
* to a hash table of a{sv}; suitable for further extension.
|
||||
*/
|
||||
GHashTable *
|
||||
rpmostree_composeutil_read_json_metadata (const char *path,
|
||||
gboolean
|
||||
rpmostree_composeutil_read_json_metadata_from_file (const char *path,
|
||||
GHashTable *metadata,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GHashTable) metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
|
||||
if (path)
|
||||
{
|
||||
const char *errprefix = glnx_strjoina ("While parsing JSON file ", path);
|
||||
GLNX_AUTO_PREFIX_ERROR (errprefix, error);
|
||||
glnx_unref_object JsonParser *jparser = json_parser_new ();
|
||||
if (!json_parser_load_from_file (jparser, path, error))
|
||||
return FALSE;
|
||||
@ -348,9 +348,6 @@ rpmostree_composeutil_read_json_metadata (const char *path,
|
||||
}
|
||||
}
|
||||
|
||||
return g_steal_pointer (&metadata);
|
||||
}
|
||||
|
||||
/* Convert hash table of metadata into finalized GVariant */
|
||||
GVariant *
|
||||
rpmostree_composeutil_finalize_metadata (GHashTable *metadata,
|
||||
|
@ -51,8 +51,9 @@ rpmostree_composeutil_get_treespec (RpmOstreeContext *ctx,
|
||||
gboolean bind_selinux,
|
||||
GError **error);
|
||||
|
||||
GHashTable *
|
||||
rpmostree_composeutil_read_json_metadata (const char *path,
|
||||
gboolean
|
||||
rpmostree_composeutil_read_json_metadata_from_file (const char *path,
|
||||
GHashTable *metadata,
|
||||
GError **error);
|
||||
|
||||
GVariant *
|
||||
|
Loading…
Reference in New Issue
Block a user