pull: Support inherit-transaction

If this is true, don't initiate, abort of commit a transaction, instead
it is assumed that the caller initiated the transaction, and that it
will eventually be commited.

This allows you to do multiple pulls or a combination of pulls and
commits in a single transaction.

Closes: #525
Approved by: cgwalters
This commit is contained in:
Alexander Larsson 2016-10-07 16:28:57 +02:00 committed by Atomic Bot
parent a0e1344cf8
commit 0446cdb0d3
1 changed files with 11 additions and 4 deletions

View File

@ -2236,6 +2236,7 @@ repo_remote_fetch_summary (OstreeRepo *self,
* * override-commit-ids (as): Array of specific commit IDs to fetch for refs * * override-commit-ids (as): Array of specific commit IDs to fetch for refs
* * dry-run (b): Only print information on what will be downloaded (requires static deltas) * * dry-run (b): Only print information on what will be downloaded (requires static deltas)
* * override-url (s): Fetch objects from this URL if remote specifies no metalink in options * * override-url (s): Fetch objects from this URL if remote specifies no metalink in options
* * inherit-transaction (b): Don't initiate, finish or abort a transaction, usefult to do mutliple pulls in one transaction.
*/ */
gboolean gboolean
ostree_repo_pull_with_options (OstreeRepo *self, ostree_repo_pull_with_options (OstreeRepo *self,
@ -2273,6 +2274,7 @@ ostree_repo_pull_with_options (OstreeRepo *self,
g_autofree char *base_meta_url = NULL; g_autofree char *base_meta_url = NULL;
g_autofree char *base_content_url = NULL; g_autofree char *base_content_url = NULL;
gboolean mirroring_into_archive; gboolean mirroring_into_archive;
gboolean inherit_transaction = FALSE;
if (options) if (options)
{ {
@ -2293,6 +2295,7 @@ ostree_repo_pull_with_options (OstreeRepo *self,
(void) g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); (void) g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids);
(void) g_variant_lookup (options, "dry-run", "b", &pull_data->dry_run); (void) g_variant_lookup (options, "dry-run", "b", &pull_data->dry_run);
(void) g_variant_lookup (options, "override-url", "&s", &url_override); (void) g_variant_lookup (options, "override-url", "&s", &url_override);
(void) g_variant_lookup (options, "inherit-transaction", "b", &inherit_transaction);
} }
g_return_val_if_fail (pull_data->maxdepth >= -1, FALSE); g_return_val_if_fail (pull_data->maxdepth >= -1, FALSE);
@ -2822,7 +2825,9 @@ ostree_repo_pull_with_options (OstreeRepo *self,
if (pull_data->fetcher == NULL) if (pull_data->fetcher == NULL)
goto out; goto out;
if (!ostree_repo_prepare_transaction (pull_data->repo, &pull_data->legacy_transaction_resuming, pull_data->legacy_transaction_resuming = FALSE;
if (!inherit_transaction &&
!ostree_repo_prepare_transaction (pull_data->repo, &pull_data->legacy_transaction_resuming,
cancellable, error)) cancellable, error))
goto out; goto out;
@ -2954,7 +2959,8 @@ ostree_repo_pull_with_options (OstreeRepo *self,
} }
} }
if (!ostree_repo_commit_transaction (pull_data->repo, NULL, cancellable, error)) if (!inherit_transaction &&
!ostree_repo_commit_transaction (pull_data->repo, NULL, cancellable, error))
goto out; goto out;
end_time = g_get_monotonic_time (); end_time = g_get_monotonic_time ();
@ -3021,6 +3027,7 @@ ostree_repo_pull_with_options (OstreeRepo *self,
else else
g_clear_error (&pull_data->cached_async_error); g_clear_error (&pull_data->cached_async_error);
if (!inherit_transaction)
ostree_repo_abort_transaction (pull_data->repo, cancellable, NULL); ostree_repo_abort_transaction (pull_data->repo, cancellable, NULL);
g_main_context_unref (pull_data->main_context); g_main_context_unref (pull_data->main_context);
if (update_timeout) if (update_timeout)