-
Notifications
You must be signed in to change notification settings - Fork 216
compose: Add --ex-lockfile and --ex-write-lockfile-to #1745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -469,3 +469,96 @@ rpmostree_composeutil_write_composejson (OstreeRepo *repo, | |
|
|
||
| return TRUE; | ||
| } | ||
|
|
||
| /* Implements --write-lockfile-to. | ||
| * If `path` is NULL, this is a NO-OP. | ||
| */ | ||
| gboolean | ||
| rpmostree_composeutil_write_lockfilejson (RpmOstreeContext *ctx, | ||
| const char *path, | ||
| GError **error) | ||
| { | ||
| if (!path) | ||
| return TRUE; | ||
|
|
||
| g_autoptr(GPtrArray) pkgs = rpmostree_context_get_packages (ctx); | ||
| g_assert (pkgs); | ||
|
|
||
| g_auto(GVariantBuilder) builder; | ||
| g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); | ||
|
|
||
| g_autoptr(GVariant) pkglist_v = NULL; | ||
| if (!rpmostree_create_pkglist_variant (pkgs, &pkglist_v, NULL, error)) | ||
| return FALSE; | ||
| g_variant_builder_add (&builder, "{sv}", "packages", pkglist_v); | ||
|
|
||
| g_autoptr(GVariant) lock_v = g_variant_builder_end (&builder); | ||
| g_assert (lock_v != NULL); | ||
| g_autoptr(JsonNode) lock_node = json_gvariant_serialize (lock_v); | ||
| g_assert (lock_node != NULL); | ||
| glnx_unref_object JsonGenerator *generator = json_generator_new (); | ||
| json_generator_set_root (generator, lock_node); | ||
| /* Let's make it somewhat introspectable by humans */ | ||
| json_generator_set_pretty (generator, TRUE); | ||
|
|
||
| char *dnbuf = strdupa (path); | ||
| const char *dn = dirname (dnbuf); | ||
| g_auto(GLnxTmpfile) tmpf = { 0, }; | ||
| if (!glnx_open_tmpfile_linkable_at (AT_FDCWD, dn, O_WRONLY | O_CLOEXEC, &tmpf, error)) | ||
| return FALSE; | ||
| g_autoptr(GOutputStream) out = g_unix_output_stream_new (tmpf.fd, FALSE); | ||
| /* See also similar code in status.c */ | ||
| if (json_generator_to_stream (generator, out, NULL, error) <= 0 || | ||
| (error != NULL && *error != NULL)) | ||
| return FALSE; | ||
|
|
||
| /* World readable to match --write-commitid-to which uses mask */ | ||
| if (!glnx_fchmod (tmpf.fd, 0644, error)) | ||
| return FALSE; | ||
|
|
||
| if (!glnx_link_tmpfile_at (&tmpf, GLNX_LINK_TMPFILE_REPLACE, AT_FDCWD, path, error)) | ||
| return FALSE; | ||
|
|
||
| return TRUE; | ||
| } | ||
|
|
||
| /* compose tree accepts JSON package version lock via file; | ||
| * convert it to a hash table of a{sv}; suitable for further extension. | ||
| */ | ||
| GHashTable * | ||
| rpmostree_composeutil_get_vlockmap (const char *path, | ||
| GError **error) | ||
| { | ||
| g_autoptr(JsonParser) parser = json_parser_new_immutable (); | ||
| if (!json_parser_load_from_file (parser, path, error)) | ||
| return glnx_null_throw (error, "Could not load lockfile %s", path); | ||
|
|
||
| JsonNode *metarootval = json_parser_get_root (parser); | ||
| g_autoptr(GVariant) jsonmetav = json_gvariant_deserialize (metarootval, "a{sv}", error); | ||
| if (!jsonmetav) | ||
| return glnx_null_throw (error, "Could not parse %s", path); | ||
|
|
||
| g_autoptr(GVariant) value = g_variant_lookup_value (jsonmetav, "packages", G_VARIANT_TYPE ("av")); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried, it doesn't work. The parsed json is like this as you can see, everything is wrapped inside a GVariant. Unless I'm missing something.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh hmm, yeah I see what you mean. Seems like that's just how |
||
| if (!value) | ||
| return glnx_null_throw (error, "Failed to find \"packages\" section in lockfile"); | ||
|
|
||
| g_autoptr(GHashTable) nevra_to_chksum = | ||
| g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); | ||
|
|
||
| GVariantIter iter; | ||
| g_variant_iter_init (&iter, value); | ||
| GVariant *child; | ||
| while (g_variant_iter_loop (&iter, "v", &child)) | ||
| { | ||
| char *nevra = NULL, *repochksum = NULL; | ||
| g_autoptr(GVariant) nv = g_variant_get_child_value (child, 0); | ||
| g_autoptr(GVariant) nvv = g_variant_get_variant (nv); | ||
| nevra = g_variant_dup_string (nvv, NULL); | ||
| g_autoptr(GVariant) cv = g_variant_get_child_value (child, 1); | ||
| g_autoptr(GVariant) cvv = g_variant_get_variant (cv); | ||
| repochksum = g_variant_dup_string (cvv, NULL); | ||
| g_hash_table_insert (nevra_to_chksum, nevra, repochksum); | ||
| } | ||
|
|
||
| return g_steal_pointer (&nevra_to_chksum); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -363,6 +363,8 @@ rpmostree_context_finalize (GObject *object) | |
| g_clear_pointer (&rctx->pkgs_to_remove, g_hash_table_unref); | ||
| g_clear_pointer (&rctx->pkgs_to_replace, g_hash_table_unref); | ||
|
|
||
| g_clear_pointer (&rctx->vlockmap, g_hash_table_unref); | ||
|
|
||
| (void)glnx_tmpdir_delete (&rctx->tmpdir, NULL, NULL); | ||
| (void)glnx_tmpdir_delete (&rctx->repo_tmpdir, NULL, NULL); | ||
|
|
||
|
|
@@ -1952,12 +1954,19 @@ rpmostree_context_prepare (RpmOstreeContext *self, | |
|
|
||
| /* And finally, handle repo packages to install */ | ||
| g_autoptr(GPtrArray) missing_pkgs = NULL; | ||
| DnfSack *sack = dnf_context_get_sack (dnfctx); | ||
| for (char **it = pkgnames; it && *it; it++) | ||
| { | ||
| const char *pkgname = *it; | ||
| g_autoptr(GError) local_error = NULL; | ||
| g_autoptr(DnfPackage) pkg = rpmostree_get_locked_package (sack, self->vlockmap, pkgname); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either should conditionalize this bit on |
||
| if (pkg) | ||
| { | ||
| hy_goal_install (goal, pkg); | ||
| continue; | ||
| } | ||
|
|
||
| g_assert (!self->rojig_pure); | ||
| g_autoptr(GError) local_error = NULL; | ||
| if (!dnf_context_install (dnfctx, pkgname, &local_error)) | ||
| { | ||
| /* Only keep going if it's ENOENT, so we coalesce into one msg at the end */ | ||
|
|
@@ -2064,6 +2073,13 @@ rpmostree_context_get_packages_to_import (RpmOstreeContext *self) | |
| return g_ptr_array_ref (self->pkgs_to_import); | ||
| } | ||
|
|
||
| void | ||
| rpmostree_context_set_vlockmap (RpmOstreeContext *self, GHashTable *map) | ||
| { | ||
| g_clear_pointer (&self->vlockmap, (GDestroyNotify)g_hash_table_unref); | ||
| self->vlockmap = g_hash_table_ref (map); | ||
| } | ||
|
|
||
| /* XXX: push this into libdnf */ | ||
| static const char* | ||
| convert_dnf_action_to_string (DnfStateAction action) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1257,6 +1257,60 @@ rpmostree_create_rpmdb_pkglist_variant (int dfd, | |
| return TRUE; | ||
| } | ||
|
|
||
| gboolean | ||
| rpmostree_create_pkglist_variant (GPtrArray *pkglist, | ||
| GVariant **out_variant, | ||
| GCancellable *cancellable, | ||
| GError **error) | ||
| { | ||
| /* we insert it sorted here so it can efficiently be searched on retrieval */ | ||
| g_ptr_array_sort (pkglist, (GCompareFunc)rpmostree_pkg_array_compare); | ||
|
|
||
| GVariantBuilder pkglist_v_builder; | ||
| g_variant_builder_init (&pkglist_v_builder, G_VARIANT_TYPE ("a(ss)")); | ||
| for (guint i = 0; i < pkglist->len; i++) | ||
| { | ||
| DnfPackage *pkg = pkglist->pdata[i]; | ||
| g_autofree gchar *repodata_chksum = NULL; | ||
|
|
||
| if (!rpmostree_get_repodata_chksum_repr (pkg, &repodata_chksum, error)) | ||
| return FALSE; | ||
|
|
||
| g_variant_builder_add (&pkglist_v_builder, "(ss)", | ||
| dnf_package_get_nevra (pkg), | ||
| repodata_chksum); | ||
| } | ||
|
|
||
| *out_variant = g_variant_ref_sink (g_variant_builder_end (&pkglist_v_builder)); | ||
| return TRUE; | ||
| } | ||
|
|
||
| DnfPackage * | ||
| rpmostree_get_locked_package (DnfSack *sack, | ||
| GHashTable *lockmap, | ||
| const char *name) | ||
| { | ||
| if (!lockmap || !name) | ||
| return NULL; | ||
|
|
||
| /* The manifest might specify not only package names (foo-1.x) but also | ||
| * something-that-foo-provides */ | ||
| g_autoptr(GPtrArray) alts = rpmostree_get_matching_packages (sack, name); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I know I suggested this, but I'm not completely satisfied either with how "indirect" it all seems. One root issue here of course is #731; libsolv simply doesn't make it easy to provide resolution information. (It's not entirely its fault either; depsolving is a hard problem that isn't exactly disposed to provide clear cut answers to these sorts of questions). Anyway, good to roll with this for now! Though it might need more thinking and tweaks in the future.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just couldn't help thinking about this a bit more :) ISTM like in the lockfile case, maybe we do want to require manifests to not use "provides" but instead purely pkgnames. So e.g. when using But yeah, I'm happy getting this in as is for now, and then tweak it in follow-ups!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tiny downside of course is that it requires slightly more churn on treefile writers to react to things like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up to this in #1849. |
||
|
|
||
| for (gsize i = 0; i < alts->len; i++) | ||
| { | ||
| DnfPackage *pkg = alts->pdata[i]; | ||
| g_autofree gchar *repodata_chksum = NULL; | ||
| if (!rpmostree_get_repodata_chksum_repr (pkg, &repodata_chksum, NULL)) | ||
| continue; | ||
|
|
||
| const char *chksum = g_hash_table_lookup (lockmap, dnf_package_get_nevra (pkg)); | ||
| if (chksum && !g_strcmp0 (chksum, repodata_chksum)) | ||
| return g_object_ref (pkg); | ||
| } | ||
| return NULL; | ||
| } | ||
|
|
||
| /* Simple wrapper around hy_split_nevra() that adds allow-none and GError convention */ | ||
| gboolean | ||
| rpmostree_decompose_nevra (const char *nevra, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/bin/bash | ||
| set -xeuo pipefail | ||
|
|
||
| dn=$(cd $(dirname $0) && pwd) | ||
| . ${dn}/libcomposetest.sh | ||
|
|
||
| prepare_compose_test "lockfile" | ||
| # Add a local rpm-md repo so we can mutate local test packages | ||
| pyappendjsonmember "repos" '["test-repo"]' | ||
| build_rpm test-pkg \ | ||
| files "/usr/bin/test-pkg" \ | ||
| install "mkdir -p %{buildroot}/usr/bin && echo localpkg data > %{buildroot}/usr/bin/test-pkg" | ||
| # The test suite writes to pwd, but we need repos in composedata | ||
| # Also we need to disable gpgcheck | ||
| echo gpgcheck=0 >> yumrepo.repo | ||
| ln yumrepo.repo composedata/test-repo.repo | ||
| pyappendjsonmember "packages" '["test-pkg"]' | ||
| pysetjsonmember "documentation" 'False' | ||
| mkdir cache | ||
| # Create lockfile | ||
| runcompose --ex-write-lockfile-to=$PWD/versions.lock --cachedir $(pwd)/cache | ||
| npkgs=$(rpm-ostree --repo=${repobuild} db list ${treeref} |grep -v '^ostree commit' | wc -l) | ||
| echo "npkgs=${npkgs}" | ||
| rpm-ostree --repo=${repobuild} db list ${treeref} test-pkg >test-pkg-list.txt | ||
| assert_file_has_content test-pkg-list.txt 'test-pkg-1.0-1.x86_64' | ||
| echo "ok compose" | ||
|
|
||
| assert_has_file "versions.lock" | ||
| assert_file_has_content $PWD/versions.lock 'packages' | ||
| assert_file_has_content $PWD/versions.lock 'test-pkg-1.0-1.x86_64' | ||
| echo "lockfile created" | ||
| # Read lockfile back | ||
| build_rpm test-pkg \ | ||
| version 2.0 \ | ||
| files "/usr/bin/test-pkg" \ | ||
| install "mkdir -p %{buildroot}/usr/bin && echo localpkg data > %{buildroot}/usr/bin/test-pkg" | ||
| runcompose --ex-lockfile=$PWD/versions.lock --cachedir $(pwd)/cache | ||
| echo "ok compose with lockfile" | ||
|
|
||
| rpm-ostree --repo=${repobuild} db list ${treeref} test-pkg >test-pkg-list.txt | ||
| assert_file_has_content test-pkg-list.txt 'test-pkg-1.0-1.x86_64' | ||
| echo "lockfile read" |
Uh oh!
There was an error while loading. Please reload this page.