diff options
author | Colin Walters <walters@verbum.org> | 2022-06-12 10:48:39 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2022-06-12 10:48:39 -0400 |
commit | 2fe0ea73955c585f9d3fa4989318e73ad21a4015 (patch) | |
tree | 82efeb273e829ef68d97c245c57d75cbd7e372a3 /src/ostree/ot-builtin-fsck.c | |
parent | e6ad897850d3f13a0dd558f314afb6bf9d3c26a6 (diff) | |
download | ostree-2fe0ea73955c585f9d3fa4989318e73ad21a4015.tar.gz |
fsck: De-indent loop
Could have done this in the previous change, but wanted to avoid
excessive diff noise.
Diffstat (limited to 'src/ostree/ot-builtin-fsck.c')
-rw-r--r-- | src/ostree/ot-builtin-fsck.c | 170 |
1 files changed, 80 insertions, 90 deletions
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c index 77ad6a4f..2c104c9e 100644 --- a/src/ostree/ot-builtin-fsck.c +++ b/src/ostree/ot-builtin-fsck.c @@ -314,112 +314,102 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, g_assert (objtype == OSTREE_OBJECT_TYPE_COMMIT); - if (TRUE) // Temporarily avoiding the noise of de-indenting this whole thing + if (!ostree_repo_load_commit (repo, checksum, &commit, &commitstate, error)) + return FALSE; + /* If requested, check that all the refs listed in the ref-bindings + * for this commit resolve back to this commit. */ + if (opt_verify_back_refs) { - if (!ostree_repo_load_commit (repo, checksum, &commit, &commitstate, error)) - return FALSE; - - /* If requested, check that all the refs listed in the ref-bindings - * for this commit resolve back to this commit. */ - if (opt_verify_back_refs) + g_autoptr(GVariant) metadata = g_variant_get_child_value (commit, 0); + const char *collection_id = NULL; + if (!g_variant_lookup (metadata, + OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, + "&s", + &collection_id)) + collection_id = NULL; + g_autofree const char **refs = NULL; + if (g_variant_lookup (metadata, + OSTREE_COMMIT_META_KEY_REF_BINDING, + "^a&s", + &refs)) { - g_autoptr(GVariant) metadata = g_variant_get_child_value (commit, 0); - - const char *collection_id = NULL; - if (!g_variant_lookup (metadata, - OSTREE_COMMIT_META_KEY_COLLECTION_BINDING, - "&s", - &collection_id)) - collection_id = NULL; - - g_autofree const char **refs = NULL; - if (g_variant_lookup (metadata, - OSTREE_COMMIT_META_KEY_REF_BINDING, - "^a&s", - &refs)) + for (const char **iter = refs; *iter != NULL; ++iter) { - for (const char **iter = refs; *iter != NULL; ++iter) + g_autofree char *checksum_for_ref = NULL; + if (collection_id != NULL) + { + const OstreeCollectionRef collection_ref = { (char *) collection_id, (char *) *iter }; + if (!ostree_repo_resolve_collection_ref (repo, &collection_ref, + TRUE, + OSTREE_REPO_RESOLVE_REV_EXT_NONE, + &checksum_for_ref, + cancellable, + error)) + return FALSE; + } + else + { + if (!ostree_repo_resolve_rev (repo, *iter, TRUE, + &checksum_for_ref, error)) + return FALSE; + } + if (checksum_for_ref == NULL) + { + if (collection_id != NULL) + return glnx_throw (error, + "Collection–ref (%s, %s) in bindings for commit %s does not exist", + collection_id, *iter, checksum); + else + return glnx_throw (error, + "Ref ‘%s’ in bindings for commit %s does not exist", + *iter, checksum); + } + else if (g_strcmp0 (checksum_for_ref, checksum) != 0) { - g_autofree char *checksum_for_ref = NULL; - if (collection_id != NULL) - { - const OstreeCollectionRef collection_ref = { (char *) collection_id, (char *) *iter }; - if (!ostree_repo_resolve_collection_ref (repo, &collection_ref, - TRUE, - OSTREE_REPO_RESOLVE_REV_EXT_NONE, - &checksum_for_ref, - cancellable, - error)) - return FALSE; - } + return glnx_throw (error, + "Collection–ref (%s, %s) in bindings for commit %s does not resolve to that commit", + collection_id, *iter, checksum); else - { - if (!ostree_repo_resolve_rev (repo, *iter, TRUE, - &checksum_for_ref, error)) - return FALSE; - } - - if (checksum_for_ref == NULL) - { - if (collection_id != NULL) - return glnx_throw (error, - "Collection–ref (%s, %s) in bindings for commit %s does not exist", - collection_id, *iter, checksum); - else - return glnx_throw (error, - "Ref ‘%s’ in bindings for commit %s does not exist", - *iter, checksum); - } - else if (g_strcmp0 (checksum_for_ref, checksum) != 0) - { - if (collection_id != NULL) - return glnx_throw (error, - "Collection–ref (%s, %s) in bindings for commit %s does not resolve to that commit", - collection_id, *iter, checksum); - else - return glnx_throw (error, - "Ref ‘%s’ in bindings for commit %s does not resolve to that commit", - *iter, checksum); - } + return glnx_throw (error, + "Ref ‘%s’ in bindings for commit %s does not resolve to that commit", + *iter, checksum); } } } - - if (opt_add_tombstones) + } + if (opt_add_tombstones) + { + GError *local_error = NULL; + g_autofree char *parent = ostree_commit_get_parent (commit); + if (parent) { - GError *local_error = NULL; - g_autofree char *parent = ostree_commit_get_parent (commit); - if (parent) + g_autoptr(GVariant) parent_commit = NULL; + if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, parent, + &parent_commit, &local_error)) { - g_autoptr(GVariant) parent_commit = NULL; - if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, parent, - &parent_commit, &local_error)) + if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { - if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) - { - g_ptr_array_add (tombstones, g_strdup (checksum)); - g_clear_error (&local_error); - } - else - { - g_propagate_error (error, local_error); - return FALSE; - } + g_ptr_array_add (tombstones, g_strdup (checksum)); + g_clear_error (&local_error); + } + else + { + g_propagate_error (error, local_error); + return FALSE; } } } - - if (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) - { - n_partial++; - if (commitstate & OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL) - n_fsck_partial++; - } - else - g_hash_table_add (commits, g_variant_ref (serialized_key)); } - } + if (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) + { + n_partial++; + if (commitstate & OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL) + n_fsck_partial++; + } + else + g_hash_table_add (commits, g_variant_ref (serialized_key)); + } g_clear_pointer (&all_commits, g_hash_table_unref); |