summaryrefslogtreecommitdiff
path: root/src/ostree/ot-builtin-fsck.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2018-04-06 15:39:43 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-04-14 15:36:21 +0000
commit474556b95547d75fe1cc4c2131a878489c7a3f82 (patch)
tree551ea7147b911364800c2fc87953582fa6f8f88c /src/ostree/ot-builtin-fsck.c
parentf258e9e5ff25e5c814bb54e4eb27e34841e913e5 (diff)
downloadostree-474556b95547d75fe1cc4c2131a878489c7a3f82.tar.gz
fsck: Mark commits with missing or deleted object partial
This means we can later use various operations to heal the repository because ostree does not assume all objects are there. This the begining of a fix for https://github.com/ostreedev/ostree/pull/345 Closes: #1533 Approved by: cgwalters
Diffstat (limited to 'src/ostree/ot-builtin-fsck.c')
-rw-r--r--src/ostree/ot-builtin-fsck.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c
index 3f9da783..8a44b619 100644
--- a/src/ostree/ot-builtin-fsck.c
+++ b/src/ostree/ot-builtin-fsck.c
@@ -53,6 +53,8 @@ static gboolean
fsck_one_object (OstreeRepo *repo,
const char *checksum,
OstreeObjectType objtype,
+ GHashTable *object_parents,
+ GVariant *key,
gboolean *out_found_corruption,
GCancellable *cancellable,
GError **error)
@@ -60,12 +62,14 @@ fsck_one_object (OstreeRepo *repo,
g_autoptr(GError) temp_error = NULL;
if (!ostree_repo_fsck_object (repo, objtype, checksum, cancellable, &temp_error))
{
+ gboolean object_missing = FALSE;
+
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_clear_error (&temp_error);
g_printerr ("Object missing: %s.%s\n", checksum,
ostree_object_type_to_string (objtype));
- *out_found_corruption = TRUE;
+ object_missing = TRUE;
}
else
{
@@ -73,7 +77,7 @@ fsck_one_object (OstreeRepo *repo,
{
g_printerr ("%s\n", temp_error->message);
(void) ostree_repo_delete_object (repo, objtype, checksum, cancellable, NULL);
- *out_found_corruption = TRUE;
+ object_missing = TRUE;
}
else
{
@@ -81,6 +85,26 @@ fsck_one_object (OstreeRepo *repo,
return FALSE;
}
}
+
+ if (object_missing)
+ {
+ *out_found_corruption = TRUE;
+
+ if (object_parents != NULL && objtype != OSTREE_OBJECT_TYPE_COMMIT)
+ {
+ g_auto(GStrv) parent_commits = ostree_repo_traverse_parents_get_commits (object_parents, key);
+ int i;
+
+ /* The commit was missing or deleted, mark the commit partial */
+ for (i = 0; parent_commits[i] != NULL; i++)
+ {
+ const char *parent_commit = parent_commits[i];
+ g_printerr ("Marking commit %s as partial\n", parent_commit);
+ if (!ostree_repo_mark_commit_partial (repo, parent_commit, TRUE, error))
+ return FALSE;
+ }
+ }
+ }
}
return TRUE;
@@ -94,6 +118,7 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo,
GError **error)
{
g_autoptr(GHashTable) reachable_objects = ostree_repo_traverse_new_reachable ();
+ g_autoptr(GHashTable) object_parents = ostree_repo_traverse_new_parents ();
GHashTableIter hash_iter;
gpointer key, value;
@@ -108,8 +133,8 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo,
g_assert (objtype == OSTREE_OBJECT_TYPE_COMMIT);
- if (!ostree_repo_traverse_commit_union (repo, checksum, 0, reachable_objects,
- cancellable, error))
+ if (!ostree_repo_traverse_commit_union_with_parents (repo, checksum, 0, reachable_objects, object_parents,
+ cancellable, error))
return FALSE;
}
@@ -127,8 +152,9 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo,
ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
- if (!fsck_one_object (repo, checksum, objtype, out_found_corruption,
- cancellable, error))
+ if (!fsck_one_object (repo, checksum, objtype,
+ object_parents, serialized_key,
+ out_found_corruption, cancellable, error))
return FALSE;
i++;
@@ -150,7 +176,7 @@ fsck_commit_for_ref (OstreeRepo *repo,
GError **error)
{
if (!fsck_one_object (repo, checksum, OSTREE_OBJECT_TYPE_COMMIT,
- found_corruption,
+ NULL, NULL, found_corruption,
cancellable, error))
return FALSE;