mirror of
https://github.com/ostreedev/ostree.git
synced 2024-10-26 17:25:36 +03:00
fsck: add argument --add-tombstones
It is used to create tombstones for missing commits Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
646fe139e6
commit
29c425e742
@ -78,6 +78,13 @@ Boston, MA 02111-1307, USA.
|
||||
Remove corrupted objects.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--add-tombstones</option></term>
|
||||
<listitem><para>
|
||||
Add tombstone commit for referenced but missing commits.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user