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; goto out;
if (!rpmostree_check_passwd (repo, yumroot, treefile_dirpath, treefile, if (!rpmostree_check_passwd (repo, yumroot, treefile_dirpath, treefile,
previous_checksum,
cancellable, error)) cancellable, error))
goto out; goto out;
if (!rpmostree_check_groups (repo, yumroot, treefile_dirpath, treefile, if (!rpmostree_check_groups (repo, yumroot, treefile_dirpath, treefile,
previous_checksum,
cancellable, error)) cancellable, error))
goto out; goto out;

View File

@ -272,13 +272,13 @@ rpmostree_check_passwd_groups (gboolean passwd,
GFile *yumroot, GFile *yumroot,
GFile *treefile_dirpath, GFile *treefile_dirpath,
JsonObject *treedata, JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
const char *direct = NULL; const char *direct = NULL;
const char *chk_type = "previous"; const char *chk_type = "previous";
const char *ref = NULL;
const char *commit_filepath = passwd ? "usr/lib/passwd" : "usr/lib/group"; 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_name = passwd ? "check-passwd" : "check-groups";
const char *json_conf_ign = passwd ? "ignore-removed-users" : "ignore-removed-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 (g_str_equal (chk_type, "previous"))
{
if (previous_commit != NULL)
{ {
gs_unref_object GFile *root = NULL; gs_unref_object GFile *root = NULL;
GError *tmp_error = NULL;
ref = _rpmostree_jsonutil_object_require_string_member (treedata, "ref", if (!ostree_repo_read_commit (repo, previous_commit, &root, NULL, NULL, error))
error);
if (!ref)
goto out; goto out;
if (!ostree_repo_read_commit (repo, ref, &root, NULL, NULL, &tmp_error)) old_path = g_file_resolve_relative_path (root, commit_filepath);
{
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;
} }
else else
{ {
g_propagate_error (error, tmp_error); /* Early return */
} ret = TRUE;
goto out; goto out;
} }
old_path = g_file_resolve_relative_path (root, commit_filepath);
} }
if (g_str_equal (chk_type, "file")) if (g_str_equal (chk_type, "file"))
@ -648,11 +640,13 @@ rpmostree_check_passwd (OstreeRepo *repo,
GFile *yumroot, GFile *yumroot,
GFile *treefile_dirpath, GFile *treefile_dirpath,
JsonObject *treedata, JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
return rpmostree_check_passwd_groups (TRUE, repo, yumroot, treefile_dirpath, 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, /* 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 *yumroot,
GFile *treefile_dirpath, GFile *treefile_dirpath,
JsonObject *treedata, JsonObject *treedata,
const char *previous_commit,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
return rpmostree_check_passwd_groups (TRUE, repo, yumroot, treefile_dirpath, return rpmostree_check_passwd_groups (TRUE, repo, yumroot, treefile_dirpath,
treedata, cancellable, error); treedata, previous_commit,
cancellable, error);
} }
static FILE * static FILE *

View File

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