ostree/fsck: Factor out common commit checking code
This will make upcoming commits a bit cleaner. Signed-off-by: Philip Withnall <withnall@endlessm.com> Closes: #1347 Approved by: cgwalters
This commit is contained in:
parent
8ae4869c9b
commit
1160d3a110
|
|
@ -131,6 +131,37 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check that a given commit object is valid for the ref it was looked up via.
|
||||||
|
* @collection_id will be %NULL for normal refs, and non-%NULL for collection–refs. */
|
||||||
|
static gboolean
|
||||||
|
fsck_commit_for_ref (OstreeRepo *repo,
|
||||||
|
const char *checksum,
|
||||||
|
const char *collection_id,
|
||||||
|
const char *ref_name,
|
||||||
|
gboolean *found_corruption,
|
||||||
|
GCancellable *cancellable,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
if (!fsck_one_object (repo, checksum, OSTREE_OBJECT_TYPE_COMMIT,
|
||||||
|
found_corruption,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
/* Check the commit exists. */
|
||||||
|
g_autoptr(GVariant) commit = NULL;
|
||||||
|
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
|
||||||
|
checksum, &commit, error))
|
||||||
|
{
|
||||||
|
if (collection_id != NULL)
|
||||||
|
return glnx_prefix_error (error, "Loading commit for ref (%s, %s)",
|
||||||
|
collection_id, ref_name);
|
||||||
|
else
|
||||||
|
return glnx_prefix_error (error, "Loading commit for ref %s", ref_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
|
ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
|
||||||
{
|
{
|
||||||
|
|
@ -154,20 +185,9 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation,
|
||||||
gpointer key, value;
|
gpointer key, value;
|
||||||
g_hash_table_iter_init (&hash_iter, all_refs);
|
g_hash_table_iter_init (&hash_iter, all_refs);
|
||||||
while (g_hash_table_iter_next (&hash_iter, &key, &value))
|
while (g_hash_table_iter_next (&hash_iter, &key, &value))
|
||||||
{
|
if (!fsck_commit_for_ref (repo, value, NULL, key,
|
||||||
const char *refname = key;
|
&found_corruption, cancellable, error))
|
||||||
const char *checksum = value;
|
return FALSE;
|
||||||
|
|
||||||
if (!fsck_one_object (repo, checksum, OSTREE_OBJECT_TYPE_COMMIT,
|
|
||||||
&found_corruption,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
g_autoptr(GVariant) commit = NULL;
|
|
||||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
|
|
||||||
checksum, &commit, error))
|
|
||||||
return glnx_prefix_error (error, "Loading commit for ref %s", refname);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
|
#ifdef OSTREE_ENABLE_EXPERIMENTAL_API
|
||||||
if (!opt_quiet)
|
if (!opt_quiet)
|
||||||
|
|
@ -183,12 +203,9 @@ ostree_builtin_fsck (int argc, char **argv, OstreeCommandInvocation *invocation,
|
||||||
while (g_hash_table_iter_next (&hash_iter, &key, &value))
|
while (g_hash_table_iter_next (&hash_iter, &key, &value))
|
||||||
{
|
{
|
||||||
const OstreeCollectionRef *ref = key;
|
const OstreeCollectionRef *ref = key;
|
||||||
const char *checksum = value;
|
if (!fsck_commit_for_ref (repo, value, ref->collection_id, ref->ref_name,
|
||||||
g_autoptr(GVariant) commit = NULL;
|
&found_corruption, cancellable, error))
|
||||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT,
|
return FALSE;
|
||||||
checksum, &commit, error))
|
|
||||||
return glnx_prefix_error (error, "Loading commit for ref (%s, %s)",
|
|
||||||
ref->collection_id, ref->ref_name);
|
|
||||||
}
|
}
|
||||||
#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */
|
#endif /* OSTREE_ENABLE_EXPERIMENTAL_API */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue