main: Add --delete option to fsck
This is useful for clearing out all corrupted objects locally.
This commit is contained in:
parent
c8801ae489
commit
f0c5a5f334
|
|
@ -38,6 +38,7 @@ static gboolean
|
||||||
load_and_fsck_one_object (OstreeRepo *repo,
|
load_and_fsck_one_object (OstreeRepo *repo,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
|
gboolean *out_found_corruption,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
|
@ -131,7 +132,11 @@ load_and_fsck_one_object (OstreeRepo *repo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!missing)
|
if (missing)
|
||||||
|
{
|
||||||
|
*out_found_corruption = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
gs_free guchar *computed_csum = NULL;
|
gs_free guchar *computed_csum = NULL;
|
||||||
gs_free char *tmp_checksum = NULL;
|
gs_free char *tmp_checksum = NULL;
|
||||||
|
|
@ -144,13 +149,23 @@ load_and_fsck_one_object (OstreeRepo *repo,
|
||||||
tmp_checksum = ostree_checksum_from_bytes (computed_csum);
|
tmp_checksum = ostree_checksum_from_bytes (computed_csum);
|
||||||
if (strcmp (checksum, tmp_checksum) != 0)
|
if (strcmp (checksum, tmp_checksum) != 0)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
gs_free char *msg = g_strdup_printf ("corrupted object %s.%s; actual checksum: %s",
|
||||||
"corrupted object %s.%s; actual checksum: %s",
|
|
||||||
checksum, ostree_object_type_to_string (objtype),
|
checksum, ostree_object_type_to_string (objtype),
|
||||||
tmp_checksum);
|
tmp_checksum);
|
||||||
|
if (opt_delete)
|
||||||
|
{
|
||||||
|
gs_unref_object GFile *object_path = ostree_repo_get_object_path (repo, checksum, objtype);
|
||||||
|
g_printerr ("%s\n", msg);
|
||||||
|
(void) gs_file_unlink (object_path, cancellable, NULL);
|
||||||
|
*out_found_corruption = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, msg);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
|
|
@ -160,6 +175,7 @@ load_and_fsck_one_object (OstreeRepo *repo,
|
||||||
static gboolean
|
static gboolean
|
||||||
fsck_reachable_objects_from_commits (OstreeRepo *repo,
|
fsck_reachable_objects_from_commits (OstreeRepo *repo,
|
||||||
GHashTable *commits,
|
GHashTable *commits,
|
||||||
|
gboolean *out_found_corruption,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
|
|
@ -203,7 +219,7 @@ fsck_reachable_objects_from_commits (OstreeRepo *repo,
|
||||||
|
|
||||||
ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
|
ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
|
||||||
|
|
||||||
if (!load_and_fsck_one_object (repo, checksum, objtype,
|
if (!load_and_fsck_one_object (repo, checksum, objtype, out_found_corruption,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -224,6 +240,7 @@ ostree_builtin_fsck (int argc, char **argv, GFile *repo_path, GCancellable *canc
|
||||||
GOptionContext *context;
|
GOptionContext *context;
|
||||||
GHashTableIter hash_iter;
|
GHashTableIter hash_iter;
|
||||||
gpointer key, value;
|
gpointer key, value;
|
||||||
|
gboolean found_corruption = FALSE;
|
||||||
gs_unref_object OstreeRepo *repo = NULL;
|
gs_unref_object OstreeRepo *repo = NULL;
|
||||||
gs_unref_hashtable GHashTable *objects = NULL;
|
gs_unref_hashtable GHashTable *objects = NULL;
|
||||||
gs_unref_hashtable GHashTable *commits = NULL;
|
gs_unref_hashtable GHashTable *commits = NULL;
|
||||||
|
|
@ -268,9 +285,17 @@ ostree_builtin_fsck (int argc, char **argv, GFile *repo_path, GCancellable *canc
|
||||||
g_print ("Verifying content integrity of %u commit objects...\n",
|
g_print ("Verifying content integrity of %u commit objects...\n",
|
||||||
(guint)g_hash_table_size (commits));
|
(guint)g_hash_table_size (commits));
|
||||||
|
|
||||||
if (!fsck_reachable_objects_from_commits (repo, commits, cancellable, error))
|
if (!fsck_reachable_objects_from_commits (repo, commits, &found_corruption,
|
||||||
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
if (found_corruption)
|
||||||
|
{
|
||||||
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Repository corruption encountered");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
if (context)
|
if (context)
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "1..1"
|
echo "1..2"
|
||||||
|
|
||||||
. $(dirname $0)/libtest.sh
|
. $(dirname $0)/libtest.sh
|
||||||
|
|
||||||
|
|
@ -27,8 +27,17 @@ setup_test_repository "bare"
|
||||||
$OSTREE checkout test2 checkout-test2
|
$OSTREE checkout test2 checkout-test2
|
||||||
cd checkout-test2
|
cd checkout-test2
|
||||||
chmod o+x firstfile
|
chmod o+x firstfile
|
||||||
$OSTREE fsck -q 2>/dev/null && (echo 1>&2 "fsck unexpectedly succeeded"; exit 1)
|
$OSTREE fsck -q && (echo 1>&2 "fsck unexpectedly succeeded"; exit 1)
|
||||||
chmod o-x firstfile
|
chmod o-x firstfile
|
||||||
$OSTREE fsck -q
|
$OSTREE fsck -q
|
||||||
|
|
||||||
echo "ok chmod"
|
echo "ok chmod"
|
||||||
|
|
||||||
|
cd ${test_tmpdir}
|
||||||
|
rm checkout-test2 -rf
|
||||||
|
$OSTREE checkout test2 checkout-test2
|
||||||
|
cd checkout-test2
|
||||||
|
chmod o+x firstfile
|
||||||
|
$OSTREE fsck -q --delete && (echo 1>&2 "fsck unexpectedly succeeded"; exit 1)
|
||||||
|
|
||||||
|
echo "ok chmod"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue