summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhaedrus Leeds <mwleeds@protonmail.com>2021-12-16 12:40:04 -0800
committerPhaedrus Leeds <mwleeds@protonmail.com>2021-12-17 12:26:26 -0800
commit3220bc6e1805f8eef81db680e26f756fd39d9111 (patch)
treef200df561d5b372e822d8baf565d9f2d7e6f1c97
parentef1c99a6ae82cc653691f0ceee1309f7f6a03eb4 (diff)
downloadflatpak-3220bc6e1805f8eef81db680e26f756fd39d9111.tar.gz
repair: Properly mark invalid commits as partial
Commits that are found to have missing or invalid objects need to be marked partial so that when the thing referencing them is reinstalled, the missing objects will be pulled. libostree treats non-partial commits as complete even if they're not, since verifying their completeness is an expensive operation. This exactly mirrors what the "ostree fsck" command does when it finds corruption in a commit. This fix is especially important because corrupt repos have been an issue lately so we at least need repair to work properly. Relatedly, delete invalid commit objects to ensure they are re-downloaded, though it's not clear that code path is almost ever reachable. Fixes https://github.com/flatpak/flatpak/issues/4618
-rw-r--r--app/flatpak-builtins-repair.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/app/flatpak-builtins-repair.c b/app/flatpak-builtins-repair.c
index f872fe1a..4680c6df 100644
--- a/app/flatpak-builtins-repair.c
+++ b/app/flatpak-builtins-repair.c
@@ -221,7 +221,17 @@ fsck_commit (OstreeRepo *repo,
if (!ostree_repo_load_commit (repo, checksum, &commit, &commitstate, &local_error))
{
- g_print ("%s\n", local_error->message);
+ /* This really shouldn't happen since we just fsck'd the commit, but
+ * deleting it makes the most sense.
+ */
+ if (opt_dry_run)
+ g_printerr (_("Commit invalid %s: %s\n"), checksum, local_error->message);
+ else
+ {
+ g_printerr (_("Deleting invalid commit %s: %s\n"), checksum, local_error->message);
+ (void) ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, NULL, NULL);
+ }
+
g_clear_error (&local_error);
return FSCK_STATUS_HAS_INVALID_OBJECTS;
}
@@ -240,9 +250,27 @@ fsck_commit (OstreeRepo *repo,
dirtree_status = fsck_dirtree (repo, partial, dirtree_checksum, object_status_cache);
status = MAX (status, dirtree_status);
- /* Its ok for partial commits to have missing objects */
+ /* It's ok for partial commits to have missing objects
+ * https://github.com/flatpak/flatpak/issues/4624
+ */
if (status == FSCK_STATUS_HAS_MISSING_OBJECTS && partial)
status = FSCK_STATUS_OK;
+ else if (status != FSCK_STATUS_OK && !partial)
+ {
+ if (opt_dry_run)
+ g_printerr (_("Commit should be marked partial: %s\n"), checksum);
+ else
+ {
+ g_printerr (_("Marking commit as partial: %s\n"), checksum);
+ if (!ostree_repo_mark_commit_partial_reason (repo, checksum, TRUE,
+ OSTREE_REPO_COMMIT_STATE_FSCK_PARTIAL,
+ &local_error))
+ {
+ g_printerr ("%s\n", local_error->message);
+ g_clear_error (&local_error);
+ }
+ }
+ }
return status;
}