mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-18 21:55:22 -04:00
Installation: Add flatpak_installation_create_transaction ()
This is the libflatpak entry point for doing transactions.
This commit is contained in:
committed by
Alexander Larsson
parent
bb62296785
commit
0e4948722c
@@ -30,6 +30,7 @@
|
||||
#include "flatpak-utils-private.h"
|
||||
#include "flatpak-installation.h"
|
||||
#include "flatpak-installed-ref-private.h"
|
||||
#include "flatpak-transaction-private.h"
|
||||
#include "flatpak-related-ref-private.h"
|
||||
#include "flatpak-remote-private.h"
|
||||
#include "flatpak-remote-ref-private.h"
|
||||
@@ -1623,6 +1624,41 @@ flatpak_installation_install_ref_file (FlatpakInstallation *self,
|
||||
return flatpak_remote_ref_new (coll_ref, NULL, remote, NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* flatpak_installation_create_transaction:
|
||||
* @self: a #FlatpakInstallation
|
||||
* @cancellable: (nullable): a #GCancellable
|
||||
* @error: return location for a #GError
|
||||
*
|
||||
* Creates a new #FlatpakTransaction object that can be used to do installation
|
||||
* and updates of multiple refs, as well as their dependencies, in a single
|
||||
* operation. Set the options you want on the transaction and add the
|
||||
* refs you want to install/update, then start the transaction with
|
||||
* flatpak_transaction_run ().
|
||||
*
|
||||
* Returns: (transfer full): a #FlatpakTransaction, or %NULL on failure.
|
||||
*/
|
||||
FlatpakTransaction *
|
||||
flatpak_installation_create_transaction (FlatpakInstallation *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(FlatpakDir) dir = NULL;
|
||||
g_autoptr(FlatpakDir) dir_clone = NULL;
|
||||
|
||||
dir = flatpak_installation_get_dir (self, error);
|
||||
if (dir == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Pull, prune, etc are not threadsafe, so we work on a copy */
|
||||
dir_clone = flatpak_dir_clone (dir);
|
||||
if (!flatpak_dir_ensure_repo (dir_clone, cancellable, error))
|
||||
return NULL;
|
||||
|
||||
return flatpak_transaction_new (dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* flatpak_installation_install_full:
|
||||
* @self: a #FlatpakInstallation
|
||||
|
||||
@@ -30,6 +30,7 @@ typedef struct _FlatpakInstallation FlatpakInstallation;
|
||||
#include <gio/gio.h>
|
||||
#include <flatpak-installed-ref.h>
|
||||
#include <flatpak-remote.h>
|
||||
#include <flatpak-transaction.h>
|
||||
|
||||
#define FLATPAK_TYPE_INSTALLATION flatpak_installation_get_type ()
|
||||
#define FLATPAK_INSTALLATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FLATPAK_TYPE_INSTALLATION, FlatpakInstallation))
|
||||
@@ -230,6 +231,9 @@ FLATPAK_EXTERN char * flatpak_installation_load_app_overrides (Flat
|
||||
const char *app_id,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
FLATPAK_EXTERN FlatpakTransaction *flatpak_installation_create_transaction (FlatpakInstallation *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
FLATPAK_EXTERN FlatpakInstalledRef * flatpak_installation_install (FlatpakInstallation *self,
|
||||
const char *remote_name,
|
||||
FlatpakRefKind kind,
|
||||
|
||||
@@ -1018,12 +1018,16 @@ flatpak_transaction_run (FlatpakTransaction *self,
|
||||
GList *l;
|
||||
gboolean succeeded = TRUE;
|
||||
gboolean needs_prune = FALSE;
|
||||
g_autoptr(GMainContextPopDefault) main_context = NULL;
|
||||
int i;
|
||||
|
||||
if (!self->no_pull &&
|
||||
!flatpak_transaction_update_metadata (self, cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
/* Work around ostree-pull spinning the default main context for the sync calls */
|
||||
main_context = flatpak_main_context_new_default ();
|
||||
|
||||
self->ops = g_list_reverse (self->ops);
|
||||
|
||||
for (l = self->ops; l != NULL; l = l->next)
|
||||
|
||||
@@ -496,6 +496,25 @@ flatpak_temp_dir_destroy (void *p)
|
||||
typedef GFile FlatpakTempDir;
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakTempDir, flatpak_temp_dir_destroy)
|
||||
|
||||
typedef GMainContext GMainContextPopDefault;
|
||||
static inline void
|
||||
flatpak_main_context_pop_default_destroy (void *p)
|
||||
{
|
||||
GMainContext *main_context = p;
|
||||
|
||||
if (main_context)
|
||||
g_main_context_pop_thread_default (main_context);
|
||||
}
|
||||
|
||||
static inline GMainContextPopDefault *
|
||||
flatpak_main_context_new_default (void)
|
||||
{
|
||||
GMainContext *main_context = g_main_context_new ();
|
||||
g_main_context_push_thread_default (main_context);
|
||||
return main_context;
|
||||
}
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GMainContextPopDefault, flatpak_main_context_pop_default_destroy)
|
||||
|
||||
typedef OstreeRepo FlatpakRepoTransaction;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user