diff options
author | Luca BRUNO <luca.bruno@coreos.com> | 2021-10-01 16:04:02 +0000 |
---|---|---|
committer | Luca BRUNO <luca.bruno@coreos.com> | 2021-10-05 12:23:22 +0000 |
commit | c9875345959fb4a028a7596b643d922a952277d0 (patch) | |
tree | 9fde928d4c10a451b6d91fe5b1a91368fa50f00c /src/libostree/ostree-repo-private.h | |
parent | 5bf4b1dabc12d6caee4f4899c9388a48bb4a72a3 (diff) | |
download | ostree-c9875345959fb4a028a7596b643d922a952277d0.tar.gz |
repo/private: allow committing/aborting through a transaction guard
This enhances the auto-transaction logic, augmenting the scope of a
transaction guard.
It allows committing or aborting a transaction through its guard.
It also supports tracking the completion status of a transaction
guard, avoiding double commits/aborts, while retaining the auto-cleanup
logic.
Diffstat (limited to 'src/libostree/ostree-repo-private.h')
-rw-r--r-- | src/libostree/ostree-repo-private.h | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index 67f755bd..a2666dec 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -229,36 +229,6 @@ struct OstreeRepo { OstreeRepo *parent_repo; }; -/* Taken from flatpak; may be made into public API later */ -typedef OstreeRepo _OstreeRepoAutoTransaction; -static inline void -_ostree_repo_auto_transaction_cleanup (void *p) -{ - if (p == NULL) - return; - g_return_if_fail (OSTREE_IS_REPO (p)); - - OstreeRepo *repo = p; - g_autoptr(GError) error = NULL; - - if (!ostree_repo_abort_transaction (repo, NULL, &error)) - g_warning("Failed to auto-cleanup OSTree transaction: %s", error->message); - - g_object_unref (repo); -} - -static inline _OstreeRepoAutoTransaction * -_ostree_repo_auto_transaction_start (OstreeRepo *repo, - GCancellable *cancellable, - GError **error) -{ - if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error)) - return NULL; - - return (_OstreeRepoAutoTransaction *) g_object_ref (repo); -} -G_DEFINE_AUTOPTR_CLEANUP_FUNC (_OstreeRepoAutoTransaction, _ostree_repo_auto_transaction_cleanup) - typedef struct { dev_t dev; ino_t ino; @@ -544,4 +514,39 @@ _ostree_repo_verify_bindings (const char *collection_id, GVariant *commit, GError **error); +/** + * OstreeRepoAutoTransaction: + * + * A transaction guard for a specific #OstreeRepo. It can be explicitly + * completed through abort/commit. If the guard has not been completed + * beforehand, on cleanup it is automatically aborted. + * + * Taken from flatpak; may be made into public API later + */ +typedef struct +{ + OstreeRepo *repo; +} OstreeRepoAutoTransaction; + +OstreeRepoAutoTransaction * +_ostree_repo_auto_transaction_start (OstreeRepo *repo, + GCancellable *cancellable, + GError **error); + +gboolean +_ostree_repo_auto_transaction_abort (OstreeRepoAutoTransaction *txn, + GCancellable *cancellable, + GError **error); + +gboolean +_ostree_repo_auto_transaction_commit (OstreeRepoAutoTransaction *txn, + OstreeRepoTransactionStats *out_stats, + GCancellable *cancellable, + GError **error); + +void +_ostree_repo_auto_transaction_cleanup (void *p); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoAutoTransaction, _ostree_repo_auto_transaction_cleanup); + G_END_DECLS |