compose: Raise up the code to read the previous (OSTree) commit

I'm planning to replace the caching code with something that inspects
the previous commit rather than a lookaside cache, so raise this code
up to a higher level.
This commit is contained in:
Colin Walters 2015-01-02 20:42:25 -05:00
parent ccd6bedac4
commit 3c55021a72
3 changed files with 42 additions and 37 deletions

View File

@ -727,6 +727,7 @@ rpmostree_compose_builtin_tree (int argc,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GError *temp_error = NULL;
GOptionContext *context = g_option_context_new ("- Run yum and commit the result to an OSTree repository"); GOptionContext *context = g_option_context_new ("- Run yum and commit the result to an OSTree repository");
const char *ref; const char *ref;
RpmOstreeTreeComposeContext selfdata = { NULL, }; RpmOstreeTreeComposeContext selfdata = { NULL, };
@ -738,6 +739,8 @@ rpmostree_compose_builtin_tree (int argc,
gs_free char *cached_compose_checksum = NULL; gs_free char *cached_compose_checksum = NULL;
gs_free char *new_compose_checksum = NULL; gs_free char *new_compose_checksum = NULL;
gs_unref_object GFile *cachedir = NULL; gs_unref_object GFile *cachedir = NULL;
gs_unref_object GFile *previous_root = NULL;
gs_free char *previous_checksum = NULL;
gs_unref_object GFile *yumroot = NULL; gs_unref_object GFile *yumroot = NULL;
gs_unref_object GFile *targetroot = NULL; gs_unref_object GFile *targetroot = NULL;
gs_unref_object GFile *yumroot_varcache = NULL; gs_unref_object GFile *yumroot_varcache = NULL;
@ -901,17 +904,34 @@ rpmostree_compose_builtin_tree (int argc,
goto out; goto out;
} }
yumroot = g_file_get_child (self->workdir, "rootfs.tmp");
if (!gs_shutil_rm_rf (yumroot, cancellable, error))
goto out;
targetroot = g_file_get_child (self->workdir, "rootfs");
ref = _rpmostree_jsonutil_object_require_string_member (treefile, "ref", error); ref = _rpmostree_jsonutil_object_require_string_member (treefile, "ref", error);
if (!ref) if (!ref)
goto out; goto out;
ref_unix = g_strdelimit (g_strdup (ref), "/", '_'); ref_unix = g_strdelimit (g_strdup (ref), "/", '_');
if (!ostree_repo_read_commit (repo, ref, &previous_root, &previous_checksum,
cancellable, &temp_error))
{
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_clear_error (&temp_error);
g_print ("No previous commit for %s\n", ref);
}
else
{
g_propagate_error (error, temp_error);
goto out;
}
}
else
g_print ("Previous commit: %s\n", previous_checksum);
yumroot = g_file_get_child (self->workdir, "rootfs.tmp");
if (!gs_shutil_rm_rf (yumroot, cancellable, error))
goto out;
targetroot = g_file_get_child (self->workdir, "rootfs");
bootstrap_packages = g_ptr_array_new (); bootstrap_packages = g_ptr_array_new ();
packages = g_ptr_array_new (); packages = g_ptr_array_new ();
@ -936,6 +956,7 @@ rpmostree_compose_builtin_tree (int argc,
self->serialized_treefile = g_bytes_new_take (treefile_buf, len); self->serialized_treefile = g_bytes_new_take (treefile_buf, len);
} }
if (previous_root != NULL)
{ {
gboolean generate_from_previous = TRUE; gboolean generate_from_previous = TRUE;
@ -947,7 +968,7 @@ rpmostree_compose_builtin_tree (int argc,
if (generate_from_previous) if (generate_from_previous)
{ {
if (!rpmostree_generate_passwd_from_previous (repo, yumroot, ref, if (!rpmostree_generate_passwd_from_previous (repo, yumroot, previous_root,
cancellable, error)) cancellable, error))
goto out; goto out;
} }

View File

@ -734,30 +734,14 @@ concat_passwd_file (GFile *yumroot,
gboolean gboolean
rpmostree_generate_passwd_from_previous (OstreeRepo *repo, rpmostree_generate_passwd_from_previous (OstreeRepo *repo,
GFile *yumroot, GFile *yumroot,
const char *ref, GFile *previous_root,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GError *temp_error = NULL;
gs_unref_object GFile *previous_root = NULL;
gs_unref_object GFile *yumroot_etc_group = g_file_resolve_relative_path (yumroot, "etc/group"); gs_unref_object GFile *yumroot_etc_group = g_file_resolve_relative_path (yumroot, "etc/group");
gs_unref_object GFile *out = NULL; gs_unref_object GFile *out = NULL;
if (!ostree_repo_read_commit (repo, ref, &previous_root, NULL, NULL, &temp_error))
{
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_clear_error (&temp_error);
ret = TRUE;
}
else
{
g_propagate_error (error, temp_error);
}
goto out;
}
if (!concat_passwd_file (yumroot, previous_root, "passwd", if (!concat_passwd_file (yumroot, previous_root, "passwd",
cancellable, error)) cancellable, error))
goto out; goto out;

View File

@ -43,6 +43,6 @@ rpmostree_check_groups (OstreeRepo *repo,
gboolean gboolean
rpmostree_generate_passwd_from_previous (OstreeRepo *repo, rpmostree_generate_passwd_from_previous (OstreeRepo *repo,
GFile *yumroot, GFile *yumroot,
const char *ref, GFile *previous_root,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);