bin/compose: Move /etc/{passwd,group} injection later

There's no reason to touch things in the target root *before*
we've even downloaded the repodata.  Further, doing so has
the potential trigger the "existing root" logic in libdnf if
it detects `/usr`.  This doesn't matter now since we're writing
to `/etc/`, but it will for later work, so let's put these bits
in the right place.

Prep for <https://github.com/projectatomic/rpm-ostree/pull/927>

Closes: #931
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-08-18 13:26:05 -04:00 committed by Atomic Bot
parent 932520a0c7
commit 83bd3c8d13

View File

@ -96,6 +96,7 @@ typedef struct {
RpmOstreeContext *corectx;
GFile *treefile;
GFile *previous_root;
GFile *workdir;
gboolean workdir_is_tmp;
int workdir_dfd;
@ -113,6 +114,7 @@ rpm_ostree_tree_compose_context_free (RpmOstreeTreeComposeContext *ctx)
g_clear_pointer (&ctx->treefile_context_dirs, (GDestroyNotify)g_ptr_array_unref);
g_clear_object (&ctx->corectx);
g_clear_object (&ctx->treefile);
g_clear_object (&ctx->previous_root);
if (ctx->workdir_is_tmp)
(void) glnx_shutil_rm_rf_at (AT_FDCWD, gs_file_get_path_cached (ctx->workdir), NULL, NULL);
g_clear_object (&ctx->workdir);
@ -459,6 +461,28 @@ install_packages_in_root (RpmOstreeTreeComposeContext *self,
if (!rpmostree_context_download (self->corectx, cancellable, error))
return FALSE;
/* Before we install packages, inject /etc/{passwd,group} if configured. */
g_autoptr(GFile) treefile_dirpath = g_file_get_parent (self->treefile);
gboolean generate_from_previous = TRUE;
if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treedata,
"preserve-passwd",
&generate_from_previous,
error))
return FALSE;
if (generate_from_previous)
{
if (!rpmostree_generate_passwd_from_previous (self->repo, rootfs_dfd,
treefile_dirpath,
self->previous_root, treedata,
cancellable, error))
return FALSE;
}
/* Now actually run through librpm to install the packages. Note this bit
* will be replaced in the future with a unified core:
* https://github.com/projectatomic/rpm-ostree/issues/729
*/
{ g_auto(GLnxConsoleRef) console = { 0, };
g_autoptr(DnfState) hifstate = dnf_state_new ();
@ -750,8 +774,7 @@ impl_compose_tree (const char *treefile_pathstr,
return FALSE;
}
g_autoptr(GFile) previous_root = NULL;
if (!ostree_repo_read_commit (self->repo, self->ref, &previous_root, &self->previous_checksum,
if (!ostree_repo_read_commit (self->repo, self->ref, &self->previous_root, &self->previous_checksum,
cancellable, &temp_error))
{
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
@ -846,27 +869,7 @@ impl_compose_tree (const char *treefile_pathstr,
self->serialized_treefile = g_bytes_new_take (treefile_buf, len);
}
g_autoptr(GFile) treefile_dirpath = g_file_get_parent (self->treefile);
if (TRUE)
{
gboolean generate_from_previous = TRUE;
if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treefile,
"preserve-passwd",
&generate_from_previous,
error))
return FALSE;
if (generate_from_previous)
{
if (!rpmostree_generate_passwd_from_previous (self->repo, rootfs_fd,
treefile_dirpath,
previous_root, treefile,
cancellable, error))
return FALSE;
}
}
/* Download rpm-md repos, packages, do install */
g_autofree char *new_inputhash = NULL;
{ gboolean unmodified = FALSE;
@ -899,6 +902,7 @@ impl_compose_tree (const char *treefile_pathstr,
if (g_strcmp0 (g_getenv ("RPM_OSTREE_BREAK"), "post-yum") == 0)
return FALSE;
/* Start postprocessing */
if (!rpmostree_treefile_postprocessing (rootfs_fd, self->treefile_context_dirs->pdata[0],
self->serialized_treefile, treefile,
next_version, cancellable, error))
@ -912,6 +916,7 @@ impl_compose_tree (const char *treefile_pathstr,
if (!rpmostree_copy_additional_files (yumroot, self->treefile_context_dirs->pdata[0], treefile, cancellable, error))
return FALSE;
g_autoptr(GFile) treefile_dirpath = g_file_get_parent (self->treefile);
if (!rpmostree_check_passwd (self->repo, yumroot, treefile_dirpath, treefile,
self->previous_checksum,
cancellable, error))