Merge pull request #2593 from smcv/txn-refcount
Fix abort-on-error behaviour of transactions
This commit is contained in:
commit
7fffc2e91e
|
|
@ -1689,10 +1689,10 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
g_debug ("Preparing transaction in repository %p", self);
|
g_debug ("Preparing transaction in repository %p", self);
|
||||||
|
|
||||||
/* Set up to abort the transaction if we return early from this function.
|
/* Set up to abort the transaction if we return early from this function.
|
||||||
* This needs to be manually built here due to a circular dependency. */
|
* We can't call _ostree_repo_auto_transaction_start() here, because that
|
||||||
g_autoptr(OstreeRepoAutoTransaction) txn = g_malloc(sizeof(OstreeRepoAutoTransaction));
|
* would be a circular dependency; use the lower-level version instead. */
|
||||||
|
g_autoptr(OstreeRepoAutoTransaction) txn = _ostree_repo_auto_transaction_new (self);
|
||||||
g_assert (txn != NULL);
|
g_assert (txn != NULL);
|
||||||
txn->repo = self;
|
|
||||||
|
|
||||||
memset (&self->txn.stats, 0, sizeof (OstreeRepoTransactionStats));
|
memset (&self->txn.stats, 0, sizeof (OstreeRepoTransactionStats));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -554,4 +554,8 @@ GType _ostree_repo_auto_transaction_get_type (void);
|
||||||
|
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoAutoTransaction, _ostree_repo_auto_transaction_unref);
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeRepoAutoTransaction, _ostree_repo_auto_transaction_unref);
|
||||||
|
|
||||||
|
/* Internal function to break a circular dependency:
|
||||||
|
* should not be made into public API, even if the rest is */
|
||||||
|
OstreeRepoAutoTransaction *_ostree_repo_auto_transaction_new (OstreeRepo *repo);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
|
||||||
|
|
@ -710,6 +710,32 @@ ostree_repo_auto_lock_cleanup (OstreeRepoAutoLock *auto_lock)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _ostree_repo_auto_transaction_new:
|
||||||
|
* @repo: (not nullable): an #OsreeRepo object
|
||||||
|
* @cancellable: Cancellable
|
||||||
|
* @error: a #GError
|
||||||
|
*
|
||||||
|
* Return a guard for a transaction in @repo.
|
||||||
|
*
|
||||||
|
* Do not call this function outside the OstreeRepo transaction implementation.
|
||||||
|
* Use _ostree_repo_auto_transaction_start() instead.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): an #OstreeRepoAutoTransaction guard on success,
|
||||||
|
* %NULL otherwise.
|
||||||
|
*/
|
||||||
|
OstreeRepoAutoTransaction *
|
||||||
|
_ostree_repo_auto_transaction_new (OstreeRepo *repo)
|
||||||
|
{
|
||||||
|
g_assert (repo != NULL);
|
||||||
|
|
||||||
|
OstreeRepoAutoTransaction *txn = g_malloc(sizeof(OstreeRepoAutoTransaction));
|
||||||
|
txn->atomic_refcount = 1;
|
||||||
|
txn->repo = g_object_ref (repo);
|
||||||
|
|
||||||
|
return g_steal_pointer (&txn);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _ostree_repo_auto_transaction_start:
|
* _ostree_repo_auto_transaction_start:
|
||||||
* @repo: (not nullable): an #OsreeRepo object
|
* @repo: (not nullable): an #OsreeRepo object
|
||||||
|
|
@ -731,11 +757,7 @@ _ostree_repo_auto_transaction_start (OstreeRepo *repo,
|
||||||
if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
|
if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
OstreeRepoAutoTransaction *txn = g_malloc(sizeof(OstreeRepoAutoTransaction));
|
return _ostree_repo_auto_transaction_new (repo);
|
||||||
txn->atomic_refcount = 1;
|
|
||||||
txn->repo = g_object_ref (repo);
|
|
||||||
|
|
||||||
return g_steal_pointer (&txn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue