fsck: create a tombstone when the parent is missing
authorGiuseppe Scrivano <gscrivan@redhat.com>
Thu, 5 Nov 2015 14:18:39 +0000 (15:18 +0100)
committerGiuseppe Scrivano <gscrivan@redhat.com>
Mon, 16 Nov 2015 09:57:33 +0000 (10:57 +0100)
Change the previous logic that a tombstone commit was created when
a partialcommit is found.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
src/ostree/ot-builtin-fsck.c

index b19268361baf53cef966d5fec2cfb3f0240e98d9..5afa435f521a378bb0fa0c509b6aba35b8a12992 100644 (file)
@@ -275,21 +275,41 @@ ostree_builtin_fsck (int argc, char **argv, GCancellable *cancellable, GError **
       const char *checksum;
       OstreeObjectType objtype;
       OstreeRepoCommitState commitstate = 0;
+      g_autoptr(GVariant) commit = NULL;
 
       ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
 
       if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
         {
-          if (!ostree_repo_load_commit (repo, checksum, NULL, &commitstate, error))
+          if (!ostree_repo_load_commit (repo, checksum, &commit, &commitstate, error))
             goto out;
 
-          if (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL)
+          if (opt_add_tombstones)
             {
-              n_partial++;
-
-              if (opt_add_tombstones)
-                g_ptr_array_add (tombstones, g_strdup (checksum));
+              GError *local_error = NULL;
+              const char *parent = ostree_commit_get_parent (commit);
+              if (parent)
+                {
+                  g_autoptr(GVariant) parent_commit = NULL;
+                  if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, parent,
+                                                 &parent_commit, &local_error))
+                    {
+                      if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+                        {
+                          g_ptr_array_add (tombstones, g_strdup (checksum));
+                          g_clear_error (&local_error);
+                        }
+                      else
+                        {
+                          g_propagate_error (error, local_error);
+                          goto out;
+                        }
+                    }
+                }
             }
+
+          if (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL)
+            n_partial++;
           else
             g_hash_table_insert (commits, g_variant_ref (serialized_key), serialized_key);
         }