compose: Reuse previous commit lookup in passwd checking

A future commit is going to change our parsing of the "ref" member in
treefiles, so ensure we only load it once early on in compose-tree.
We already looked up the previous commit there, so just pass it down
rather than reloading the ref.

Closes: #274
Approved by: jlebon
This commit is contained in:
Colin Walters 2016-04-28 09:09:40 -04:00 committed by Colin Walters (automation)
parent 9541cc693f
commit e2e754e94c
3 changed files with 23 additions and 23 deletions

View File

@ -845,10 +845,12 @@ rpmostree_compose_builtin_tree (int argc,
goto out;
if (!rpmostree_check_passwd (repo, yumroot, treefile_dirpath, treefile,
previous_checksum,
cancellable, error))
goto out;
if (!rpmostree_check_groups (repo, yumroot, treefile_dirpath, treefile,
previous_checksum,
cancellable, error))
goto out;

View File

@ -272,13 +272,13 @@ rpmostree_check_passwd_groups (gboolean passwd,
GFile *yumroot,
GFile *treefile_dirpath,
JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
const char *direct = NULL;
const char *chk_type = "previous";
const char *ref = NULL;
const char *commit_filepath = passwd ? "usr/lib/passwd" : "usr/lib/group";
const char *json_conf_name = passwd ? "check-passwd" : "check-groups";
const char *json_conf_ign = passwd ? "ignore-removed-users" : "ignore-removed-groups";
@ -400,30 +400,22 @@ rpmostree_check_passwd_groups (gboolean passwd,
}
if (g_str_equal (chk_type, "previous"))
{
if (previous_commit != NULL)
{
gs_unref_object GFile *root = NULL;
GError *tmp_error = NULL;
ref = _rpmostree_jsonutil_object_require_string_member (treedata, "ref",
error);
if (!ref)
if (!ostree_repo_read_commit (repo, previous_commit, &root, NULL, NULL, error))
goto out;
if (!ostree_repo_read_commit (repo, ref, &root, NULL, NULL, &tmp_error))
{
if (g_error_matches (tmp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{ /* this is kind of a hack, makes it work if it's the first commit */
g_clear_error (&tmp_error);
ret = TRUE;
old_path = g_file_resolve_relative_path (root, commit_filepath);
}
else
{
g_propagate_error (error, tmp_error);
}
/* Early return */
ret = TRUE;
goto out;
}
old_path = g_file_resolve_relative_path (root, commit_filepath);
}
if (g_str_equal (chk_type, "file"))
@ -648,11 +640,13 @@ rpmostree_check_passwd (OstreeRepo *repo,
GFile *yumroot,
GFile *treefile_dirpath,
JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable,
GError **error)
{
return rpmostree_check_passwd_groups (TRUE, repo, yumroot, treefile_dirpath,
treedata, cancellable, error);
treedata, previous_commit,
cancellable, error);
}
/* See "man 5 group" We just need to make sure the name and gid match,
@ -663,11 +657,13 @@ rpmostree_check_groups (OstreeRepo *repo,
GFile *yumroot,
GFile *treefile_dirpath,
JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable,
GError **error)
{
return rpmostree_check_passwd_groups (TRUE, repo, yumroot, treefile_dirpath,
treedata, cancellable, error);
treedata, previous_commit,
cancellable, error);
}
static FILE *

View File

@ -29,6 +29,7 @@ rpmostree_check_passwd (OstreeRepo *repo,
GFile *yumroot,
GFile *treefile_path,
JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable,
GError **error);
@ -37,6 +38,7 @@ rpmostree_check_groups (OstreeRepo *repo,
GFile *yumroot,
GFile *treefile_path,
JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable,
GError **error);