lib/traverse: Port to new style

Not prep for anything, was just reading this code a bit while
working on rpm-ostree jigdo.

Closes: #1338
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-11-09 15:54:30 -05:00 committed by Atomic Bot
parent 3e8b7e29fa
commit 6b9ce9d35d
1 changed files with 36 additions and 58 deletions

View File

@ -56,10 +56,6 @@ ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *it
{ {
struct _OstreeRepoRealCommitTraverseIter *real = struct _OstreeRepoRealCommitTraverseIter *real =
(struct _OstreeRepoRealCommitTraverseIter*)iter; (struct _OstreeRepoRealCommitTraverseIter*)iter;
gboolean ret = FALSE;
const guchar *csum;
g_autoptr(GVariant) meta_csum_bytes = NULL;
g_autoptr(GVariant) content_csum_bytes = NULL;
memset (real, 0, sizeof (*real)); memset (real, 0, sizeof (*real));
real->initialized = TRUE; real->initialized = TRUE;
@ -68,21 +64,21 @@ ostree_repo_commit_traverse_iter_init_commit (OstreeRepoCommitTraverseIter *it
real->current_dir = NULL; real->current_dir = NULL;
real->idx = 0; real->idx = 0;
g_autoptr(GVariant) content_csum_bytes = NULL;
g_variant_get_child (commit, 6, "@ay", &content_csum_bytes); g_variant_get_child (commit, 6, "@ay", &content_csum_bytes);
csum = ostree_checksum_bytes_peek_validate (content_csum_bytes, error); const guchar *csum = ostree_checksum_bytes_peek_validate (content_csum_bytes, error);
if (!csum) if (!csum)
goto out; return FALSE;
ostree_checksum_inplace_from_bytes (csum, real->checksum_content); ostree_checksum_inplace_from_bytes (csum, real->checksum_content);
g_autoptr(GVariant) meta_csum_bytes = NULL;
g_variant_get_child (commit, 7, "@ay", &meta_csum_bytes); g_variant_get_child (commit, 7, "@ay", &meta_csum_bytes);
csum = ostree_checksum_bytes_peek_validate (meta_csum_bytes, error); csum = ostree_checksum_bytes_peek_validate (meta_csum_bytes, error);
if (!csum) if (!csum)
goto out; return FALSE;
ostree_checksum_inplace_from_bytes (csum, real->checksum_meta); ostree_checksum_inplace_from_bytes (csum, real->checksum_meta);
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -312,8 +308,6 @@ traverse_iter (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
while (TRUE) while (TRUE)
{ {
g_autoptr(GVariant) key = NULL; g_autoptr(GVariant) key = NULL;
@ -330,12 +324,11 @@ traverse_iter (OstreeRepo *repo,
g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{ {
g_debug ("Ignoring not-found dirmeta"); g_debug ("Ignoring not-found dirmeta");
ret = TRUE; return TRUE; /* Note early return */
} }
else
g_propagate_error (error, g_steal_pointer (&local_error));
goto out; g_propagate_error (error, g_steal_pointer (&local_error));
return FALSE;
} }
else if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_END) else if (iterres == OSTREE_REPO_COMMIT_ITER_RESULT_END)
break; break;
@ -371,16 +364,14 @@ traverse_iter (OstreeRepo *repo,
if (!traverse_dirtree (repo, content_checksum, inout_reachable, if (!traverse_dirtree (repo, content_checksum, inout_reachable,
ignore_missing_dirs, cancellable, error)) ignore_missing_dirs, cancellable, error))
goto out; return FALSE;
} }
} }
else else
g_assert_not_reached (); g_assert_not_reached ();
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
@ -391,12 +382,9 @@ traverse_dirtree (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GVariant) dirtree = NULL;
ostree_cleanup_repo_commit_traverse_iter
OstreeRepoCommitTraverseIter iter = { 0, };
g_autoptr(GError) local_error = NULL; g_autoptr(GError) local_error = NULL;
g_autoptr(GVariant) dirtree = NULL;
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum, if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum,
&dirtree, &local_error)) &dirtree, &local_error))
{ {
@ -404,26 +392,25 @@ traverse_dirtree (OstreeRepo *repo,
g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{ {
g_debug ("Ignoring not-found dirmeta %s", checksum); g_debug ("Ignoring not-found dirmeta %s", checksum);
ret = TRUE; return TRUE; /* Early return */
} }
else
g_propagate_error (error, g_steal_pointer (&local_error));
goto out; g_propagate_error (error, g_steal_pointer (&local_error));
return FALSE;
} }
g_debug ("Traversing dirtree %s", checksum); g_debug ("Traversing dirtree %s", checksum);
ostree_cleanup_repo_commit_traverse_iter
OstreeRepoCommitTraverseIter iter = { 0, };
if (!ostree_repo_commit_traverse_iter_init_dirtree (&iter, repo, dirtree, if (!ostree_repo_commit_traverse_iter_init_dirtree (&iter, repo, dirtree,
OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE,
error)) error))
goto out; return FALSE;
if (!traverse_iter (repo, &iter, inout_reachable, ignore_missing_dirs, cancellable, error)) if (!traverse_iter (repo, &iter, inout_reachable, ignore_missing_dirs, cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -446,28 +433,21 @@ ostree_repo_traverse_commit_union (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autofree char *tmp_checksum = NULL; g_autofree char *tmp_checksum = NULL;
while (TRUE) while (TRUE)
{ {
gboolean recurse = FALSE; g_autoptr(GVariant) key =
g_autoptr(GVariant) key = NULL; g_variant_ref_sink (ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT));
g_autoptr(GVariant) commit = NULL;
ostree_cleanup_repo_commit_traverse_iter
OstreeRepoCommitTraverseIter iter = { 0, };
OstreeRepoCommitState commitstate;
gboolean ignore_missing_dirs = FALSE;
key = g_variant_ref_sink (ostree_object_name_serialize (commit_checksum, OSTREE_OBJECT_TYPE_COMMIT));
if (g_hash_table_contains (inout_reachable, key)) if (g_hash_table_contains (inout_reachable, key))
break; break;
g_autoptr(GVariant) commit = NULL;
if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT, if (!ostree_repo_load_variant_if_exists (repo, OSTREE_OBJECT_TYPE_COMMIT,
commit_checksum, &commit, commit_checksum, &commit,
error)) error))
goto out; return FALSE;
/* Just return if the parent isn't found; we do expect most /* Just return if the parent isn't found; we do expect most
* people to have partial repositories. * people to have partial repositories.
@ -476,10 +456,12 @@ ostree_repo_traverse_commit_union (OstreeRepo *repo,
break; break;
/* See if the commit is partial, if so it's not an error to lack objects */ /* See if the commit is partial, if so it's not an error to lack objects */
OstreeRepoCommitState commitstate;
if (!ostree_repo_load_commit (repo, commit_checksum, NULL, &commitstate, if (!ostree_repo_load_commit (repo, commit_checksum, NULL, &commitstate,
error)) error))
goto out; return FALSE;
gboolean ignore_missing_dirs = FALSE;
if ((commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) != 0) if ((commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) != 0)
ignore_missing_dirs = TRUE; ignore_missing_dirs = TRUE;
@ -487,14 +469,17 @@ ostree_repo_traverse_commit_union (OstreeRepo *repo,
key = NULL; key = NULL;
g_debug ("Traversing commit %s", commit_checksum); g_debug ("Traversing commit %s", commit_checksum);
ostree_cleanup_repo_commit_traverse_iter
OstreeRepoCommitTraverseIter iter = { 0, };
if (!ostree_repo_commit_traverse_iter_init_commit (&iter, repo, commit, if (!ostree_repo_commit_traverse_iter_init_commit (&iter, repo, commit,
OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE, OSTREE_REPO_COMMIT_TRAVERSE_FLAG_NONE,
error)) error))
goto out; return FALSE;
if (!traverse_iter (repo, &iter, inout_reachable, ignore_missing_dirs, cancellable, error)) if (!traverse_iter (repo, &iter, inout_reachable, ignore_missing_dirs, cancellable, error))
goto out; return FALSE;
gboolean recurse = FALSE;
if (maxdepth == -1 || maxdepth > 0) if (maxdepth == -1 || maxdepth > 0)
{ {
g_free (tmp_checksum); g_free (tmp_checksum);
@ -511,9 +496,7 @@ ostree_repo_traverse_commit_union (OstreeRepo *repo,
break; break;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
/** /**
@ -536,17 +519,12 @@ ostree_repo_traverse_commit (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; g_autoptr(GHashTable) ret_reachable = ostree_repo_traverse_new_reachable ();
g_autoptr(GHashTable) ret_reachable =
ostree_repo_traverse_new_reachable ();
if (!ostree_repo_traverse_commit_union (repo, commit_checksum, maxdepth, if (!ostree_repo_traverse_commit_union (repo, commit_checksum, maxdepth,
ret_reachable, cancellable, error)) ret_reachable, cancellable, error))
goto out; return FALSE;
ret = TRUE;
if (out_reachable) if (out_reachable)
*out_reachable = g_steal_pointer (&ret_reachable); *out_reachable = g_steal_pointer (&ret_reachable);
out: return TRUE;
return ret;
} }