core: Ensure we abort transaction if we fail in the middle
Otherwise we could leave a lot of temp files lying around.
This commit is contained in:
parent
fc1ed105b4
commit
788dfe89e1
|
|
@ -81,6 +81,7 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
GVariantBuilder metadata_builder;
|
GVariantBuilder metadata_builder;
|
||||||
gboolean metadata_builder_initialized = FALSE;
|
gboolean metadata_builder_initialized = FALSE;
|
||||||
gboolean skip_commit = FALSE;
|
gboolean skip_commit = FALSE;
|
||||||
|
gboolean in_transaction = FALSE;
|
||||||
|
|
||||||
context = g_option_context_new ("[ARG] - Commit a new revision");
|
context = g_option_context_new ("[ARG] - Commit a new revision");
|
||||||
g_option_context_add_main_entries (context, options, NULL);
|
g_option_context_add_main_entries (context, options, NULL);
|
||||||
|
|
@ -180,6 +181,8 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
if (!ostree_repo_prepare_transaction (repo, cancellable, error))
|
if (!ostree_repo_prepare_transaction (repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
in_transaction = TRUE;
|
||||||
|
|
||||||
mtree = ostree_mutable_tree_new ();
|
mtree = ostree_mutable_tree_new ();
|
||||||
|
|
||||||
if (argc == 1 && (trees == NULL || trees[0] == NULL))
|
if (argc == 1 && (trees == NULL || trees[0] == NULL))
|
||||||
|
|
@ -282,6 +285,8 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
|
|
||||||
if (!ostree_repo_commit_transaction (repo, cancellable, error))
|
if (!ostree_repo_commit_transaction (repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
in_transaction = FALSE;
|
||||||
|
|
||||||
if (!ostree_repo_write_ref (repo, NULL, branch, commit_checksum, error))
|
if (!ostree_repo_write_ref (repo, NULL, branch, commit_checksum, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -293,11 +298,17 @@ ostree_builtin_commit (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
if (!ostree_repo_abort_transaction (repo, cancellable, error))
|
if (!ostree_repo_abort_transaction (repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
in_transaction = FALSE;
|
||||||
|
|
||||||
g_print ("%s\n", parent);
|
g_print ("%s\n", parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
|
if (in_transaction)
|
||||||
|
{
|
||||||
|
(void) ostree_repo_abort_transaction (repo, cancellable, NULL);
|
||||||
|
}
|
||||||
if (metadata_builder_initialized)
|
if (metadata_builder_initialized)
|
||||||
g_variant_builder_clear (&metadata_builder);
|
g_variant_builder_clear (&metadata_builder);
|
||||||
g_clear_object (&arg);
|
g_clear_object (&arg);
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
GFile *metadata_f = NULL;
|
GFile *metadata_f = NULL;
|
||||||
OstreeMutableTree *mtree = NULL;
|
OstreeMutableTree *mtree = NULL;
|
||||||
gboolean skip_commit = FALSE;
|
gboolean skip_commit = FALSE;
|
||||||
|
gboolean in_transaction = FALSE;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
context = g_option_context_new ("BRANCH1 BRANCH2 ... - Merge multiple commits into a single commit tree");
|
context = g_option_context_new ("BRANCH1 BRANCH2 ... - Merge multiple commits into a single commit tree");
|
||||||
|
|
@ -136,6 +137,8 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
if (!ostree_repo_prepare_transaction (repo, cancellable, error))
|
if (!ostree_repo_prepare_transaction (repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
in_transaction = TRUE;
|
||||||
|
|
||||||
mtree = ostree_mutable_tree_new ();
|
mtree = ostree_mutable_tree_new ();
|
||||||
|
|
||||||
if (recompose)
|
if (recompose)
|
||||||
|
|
@ -224,6 +227,8 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
if (!ostree_repo_commit_transaction (repo, cancellable, error))
|
if (!ostree_repo_commit_transaction (repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
in_transaction = FALSE;
|
||||||
|
|
||||||
if (!ostree_repo_write_ref (repo, NULL, branch, commit_checksum, error))
|
if (!ostree_repo_write_ref (repo, NULL, branch, commit_checksum, error))
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
@ -231,6 +236,8 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
{
|
{
|
||||||
if (!ostree_repo_abort_transaction (repo, cancellable, error))
|
if (!ostree_repo_abort_transaction (repo, cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
in_transaction = FALSE;
|
||||||
|
|
||||||
g_print ("%s\n", parent);
|
g_print ("%s\n", parent);
|
||||||
}
|
}
|
||||||
|
|
@ -238,6 +245,11 @@ ostree_builtin_compose (int argc, char **argv, GFile *repo_path, GError **error)
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
g_print ("%s\n", commit_checksum);
|
g_print ("%s\n", commit_checksum);
|
||||||
out:
|
out:
|
||||||
|
if (in_transaction)
|
||||||
|
{
|
||||||
|
(void) ostree_repo_abort_transaction (repo, cancellable, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (compose_metadata_builder_initialized)
|
if (compose_metadata_builder_initialized)
|
||||||
g_variant_builder_clear (&compose_metadata_builder);
|
g_variant_builder_clear (&compose_metadata_builder);
|
||||||
if (commit_metadata_builder_initialized)
|
if (commit_metadata_builder_initialized)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue