lib: improve transactions auto-cleanup logic
authorLuca BRUNO <luca.bruno@coreos.com>
Wed, 25 Aug 2021 12:30:21 +0000 (12:30 +0000)
committerLuca BRUNO <luca.bruno@coreos.com>
Wed, 25 Aug 2021 16:17:52 +0000 (16:17 +0000)
This fixes some aspects of OstreeRepoAutoTransaction and re-aligns
it with the logic in flatpak. Specifically:
 * link to the underlying repo through refcounting
 * bridge internal errors to warning messages
 * verify the input pointer type

This is a preparation step before exposing this logic as a public API.

src/libostree/ostree-repo-private.h

index 0cd9d8bb839c1cd87c8cfb965e1497f9e45cbaad..67f755bde0b851f553a43bb249f1be95fde138c0 100644 (file)
@@ -234,9 +234,17 @@ 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;
-  if (repo)
-    (void) ostree_repo_abort_transaction (repo, NULL, NULL);
+  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 *
@@ -246,7 +254,8 @@ _ostree_repo_auto_transaction_start (OstreeRepo     *repo,
 {
   if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
     return NULL;
-  return (_OstreeRepoAutoTransaction *)repo;
+
+  return (_OstreeRepoAutoTransaction *) g_object_ref (repo);
 }
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (_OstreeRepoAutoTransaction, _ostree_repo_auto_transaction_cleanup)