From 5ecfd0ca663ed3d05d34f9bd1b8da1fff91d31b4 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Thu, 14 Sep 2017 11:51:34 +0800 Subject: [PATCH] lib: Add support for FLATPAK_INSTALL_FLAGS_NO_DEPLOY / NO_PULL We have the same flags for flatpak_installation_update and we use flatpak_dir_install from within FlatpakInstallation but always set the no_pull/no_deploy flags to FALSE. Previously, passing FLATPAK_INSTALL_FLAGS_NO_PULL and FLATPAK_INSTALL_FLAGS_NO_DEPLOY wouldn't do anything because of that. This has the unfortunate side effect of always returning an error when FLATPAK_INSTALL_FLAGS_NO_DEPLOY is passed, because flatpak_installation_install_full tries to get a FlatpakInstalledRef for the flatpak when it is installed, but obviously it can't do that since installing an app in an undeployed state doesn't "install" it so much as just cloning it to the local repository. As a result, when FLATPAK_INSTALL_FLAGS_NO_PULL is passed, the FLATPAK_ERROR_ONLY_PULLED Will be set and the caller must respond accordingly. --- lib/flatpak-error.h | 3 +++ lib/flatpak-installation.c | 32 +++++++++++++++++++++++++++++++- lib/flatpak-installation.h | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/flatpak-error.h b/lib/flatpak-error.h index 58380e17..0499aa01 100644 --- a/lib/flatpak-error.h +++ b/lib/flatpak-error.h @@ -30,12 +30,15 @@ G_BEGIN_DECLS * FlatpakError: * @FLATPAK_ERROR_ALREADY_INSTALLED: App/runtime is already installed * @FLATPAK_ERROR_NOT_INSTALLED: App/runtime is not installed + * @FLATPAK_ERROR_ONLY_PULLED: App/runtime was only pulled into the local + * repository but not installed. * * Error codes for library functions. */ typedef enum { FLATPAK_ERROR_ALREADY_INSTALLED, FLATPAK_ERROR_NOT_INSTALLED, + FLATPAK_ERROR_ONLY_PULLED } FlatpakError; #define FLATPAK_ERROR flatpak_error_quark () diff --git a/lib/flatpak-installation.c b/lib/flatpak-installation.c index f88118a5..24c2d87c 100644 --- a/lib/flatpak-installation.c +++ b/lib/flatpak-installation.c @@ -1310,6 +1310,14 @@ flatpak_installation_install_ref_file (FlatpakInstallation *self, * * Install a new application or runtime. * + * Note that this function was originally written to always return a + * #FlatpakInstalledRef. Since 0.9.12.12, passing + * FLATPAK_INSTALL_FLAGS_NO_DEPLOY will only pull refs into the local flatpak + * repository without deploying them, however this function will + * be unable to provide information on the installed ref, so + * FLATPAK_ERROR_ONLY_PULLED will be set and the caller must respond + * accordingly. + * * Returns: (transfer full): The ref for the newly installed app or %NULL on failure */ FlatpakInstalledRef * @@ -1361,12 +1369,26 @@ flatpak_installation_install_full (FlatpakInstallation *self, else ostree_progress = ostree_async_progress_new_and_connect (no_progress_cb, NULL); - if (!flatpak_dir_install (dir_clone, FALSE, FALSE, + if (!flatpak_dir_install (dir_clone, + (flags & FLATPAK_INSTALL_FLAGS_NO_PULL) != 0, + (flags & FLATPAK_INSTALL_FLAGS_NO_DEPLOY) != 0, (flags & FLATPAK_INSTALL_FLAGS_NO_STATIC_DELTAS) != 0, ref, remote_name, (const char **)subpaths, ostree_progress, cancellable, error)) goto out; + /* Note that if the caller sets FLATPAK_INSTALL_FLAGS_NO_DEPLOY we must + * always return an error, as explained above. Otherwise get_ref will + * always return an error. */ + if ((flags & FLATPAK_INSTALL_FLAGS_NO_DEPLOY) != 0) + { + g_set_error (error, + FLATPAK_ERROR, FLATPAK_ERROR_ONLY_PULLED, + "As requested, %s was only pulled, but not installed", + name); + goto out; + } + result = get_ref (dir, ref, cancellable, error); if (result == NULL) goto out; @@ -1396,6 +1418,14 @@ out: * * Install a new application or runtime. * + * Note that this function was originally written to always return a + * #FlatpakInstalledRef. Since 0.9.12.12, passing + * FLATPAK_INSTALL_FLAGS_NO_DEPLOY will only pull refs into the local flatpak + * repository without deploying them, however this function will + * be unable to provide information on the installed ref, so + * FLATPAK_ERROR_ONLY_PULLED will be set and the caller must respond + * accordingly. + * * Returns: (transfer full): The ref for the newly installed app or %NULL on failure */ FlatpakInstalledRef * diff --git a/lib/flatpak-installation.h b/lib/flatpak-installation.h index 94be2ff1..1e0a8627 100644 --- a/lib/flatpak-installation.h +++ b/lib/flatpak-installation.h @@ -71,6 +71,8 @@ typedef enum { typedef enum { FLATPAK_INSTALL_FLAGS_NONE = 0, FLATPAK_INSTALL_FLAGS_NO_STATIC_DELTAS = (1 << 0), + FLATPAK_INSTALL_FLAGS_NO_DEPLOY = (1 << 2), + FLATPAK_INSTALL_FLAGS_NO_PULL = (1 << 3), } FlatpakInstallFlags; /**