From 29c425e742accc9651bb9bc2c0c6e5bbc602cc24 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 28 Oct 2015 14:23:35 +0100 Subject: [PATCH] fsck: add argument --add-tombstones It is used to create tombstones for missing commits Signed-off-by: Giuseppe Scrivano --- doc/ostree-fsck.xml | 7 +++++++ src/ostree/ot-builtin-fsck.c | 38 ++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/ostree-fsck.xml b/doc/ostree-fsck.xml index 68107f53..2cae92cf 100644 --- a/doc/ostree-fsck.xml +++ b/doc/ostree-fsck.xml @@ -78,6 +78,13 @@ Boston, MA 02111-1307, USA. Remove corrupted objects. + + + + + Add tombstone commit for referenced but missing commits. + + diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c index 69bb2e46..d16ead84 100644 --- a/src/ostree/ot-builtin-fsck.c +++ b/src/ostree/ot-builtin-fsck.c @@ -30,8 +30,10 @@ static gboolean opt_quiet; static gboolean opt_delete; +static gboolean opt_add_tombstones; static GOptionEntry options[] = { + { "add-tombstones", 0, 0, G_OPTION_ARG_NONE, &opt_add_tombstones, "Add tombstones for missing commits", NULL }, { "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, "Only print error messages", NULL }, { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Remove corrupted objects", NULL }, { NULL } @@ -246,7 +248,7 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError ** guint n_partial = 0; g_autoptr(GHashTable) objects = NULL; g_autoptr(GHashTable) commits = NULL; - + g_autoptr(GPtrArray) tombstones = NULL; context = g_option_context_new ("- Check the repository for consistency"); if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error)) @@ -264,6 +266,9 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError ** g_hash_table_iter_init (&hash_iter, objects); + if (opt_add_tombstones) + tombstones = g_ptr_array_new_with_free_func (g_free); + while (g_hash_table_iter_next (&hash_iter, &key, &value)) { GVariant *serialized_key = key; @@ -281,6 +286,9 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError ** if (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) { n_partial++; + + if (opt_add_tombstones) + g_ptr_array_add (tombstones, g_strdup (checksum)); } else g_hash_table_insert (commits, g_variant_ref (serialized_key), serialized_key); @@ -297,7 +305,33 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError ** cancellable, error)) goto out; - if (n_partial > 0) + if (opt_add_tombstones) + { + guint i; + if (tombstones->len) + { + GError *temp_error = NULL; + gboolean tombstone_commits = FALSE; + GKeyFile *config = ostree_repo_get_config (repo); + tombstone_commits = g_key_file_get_boolean (config, "core", "tombstone-commits", &temp_error); + /* tombstone_commits is FALSE either if it is not found or it is really set to FALSE in the config file. */ + if (!tombstone_commits) + { + g_clear_error (&temp_error); + g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE); + if (!ostree_repo_write_config (repo, config, error)) + goto out; + } + } + for (i = 0; i < tombstones->len; i++) + { + const char *checksum = tombstones->pdata[i]; + g_print ("Adding tombstone for commit %s\n", checksum); + if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, cancellable, error)) + goto out; + } + } + else if (n_partial > 0) { g_print ("%u partial commits not verified\n", n_partial); }