mirror of
https://github.com/flatpak/flatpak.git
synced 2026-05-16 12:50:01 -04:00
common: support reinstall option on bundle installations
Fixes #2489
Adds and wires up a `reinstall` option to
`flatpak_dir_install_bundle`. Previously, bundle install
transactions would silently drop the reinstall flag.
(backported from commit 919d2922bf)
This commit is contained in:
committed by
Sebastian Wick
parent
159796af54
commit
4c5693b892
@@ -239,9 +239,11 @@ typedef enum {
|
||||
typedef enum {
|
||||
FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_NONE = 0,
|
||||
FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_NO_INTERACTION = 1 << 0,
|
||||
FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_REINSTALL = 1 << 1,
|
||||
} FlatpakHelperInstallBundleFlags;
|
||||
|
||||
#define FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_ALL (FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_NO_INTERACTION)
|
||||
#define FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_ALL (FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_NO_INTERACTION | \
|
||||
FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_REINSTALL)
|
||||
|
||||
typedef enum {
|
||||
FLATPAK_HELPER_DEPLOY_APPSTREAM_FLAGS_NONE = 0,
|
||||
@@ -710,6 +712,7 @@ char * flatpak_dir_ensure_bundle_remote (Fla
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean flatpak_dir_install_bundle (FlatpakDir *self,
|
||||
gboolean reinstall,
|
||||
GFile *file,
|
||||
const char *remote,
|
||||
FlatpakDecomposed **out_ref,
|
||||
|
||||
@@ -10302,6 +10302,7 @@ flatpak_dir_check_add_remotes_config_dir (FlatpakDir *self,
|
||||
|
||||
gboolean
|
||||
flatpak_dir_install_bundle (FlatpakDir *self,
|
||||
gboolean reinstall,
|
||||
GFile *file,
|
||||
const char *remote,
|
||||
FlatpakDecomposed **out_ref,
|
||||
@@ -10315,6 +10316,7 @@ flatpak_dir_install_bundle (FlatpakDir *self,
|
||||
g_autofree char *origin = NULL;
|
||||
g_autofree char *to_checksum = NULL;
|
||||
gboolean gpg_verify;
|
||||
FlatpakHelperInstallBundleFlags install_flags = FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_NONE;
|
||||
|
||||
if (!flatpak_dir_check_add_remotes_config_dir (self, error))
|
||||
return FALSE;
|
||||
@@ -10323,9 +10325,13 @@ flatpak_dir_install_bundle (FlatpakDir *self,
|
||||
{
|
||||
const char *installation = flatpak_dir_get_id (self);
|
||||
|
||||
if (reinstall)
|
||||
install_flags |= FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_REINSTALL;
|
||||
|
||||
if (!flatpak_dir_system_helper_call_install_bundle (self,
|
||||
flatpak_file_get_path_cached (file),
|
||||
0, remote,
|
||||
install_flags,
|
||||
remote,
|
||||
installation ? installation : "",
|
||||
&ref_str,
|
||||
cancellable,
|
||||
@@ -10360,17 +10366,30 @@ flatpak_dir_install_bundle (FlatpakDir *self,
|
||||
{
|
||||
if (strcmp (flatpak_deploy_data_get_commit (deploy_data), to_checksum) == 0)
|
||||
{
|
||||
g_autofree char *id = flatpak_decomposed_dup_id (ref);
|
||||
g_set_error (error, FLATPAK_ERROR, FLATPAK_ERROR_ALREADY_INSTALLED,
|
||||
_("This version of %s is already installed"), id);
|
||||
return FALSE;
|
||||
if (reinstall)
|
||||
{
|
||||
g_clear_pointer (&deploy_data, g_bytes_unref);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_autofree char *id = flatpak_decomposed_dup_id (ref);
|
||||
g_set_error (error, FLATPAK_ERROR, FLATPAK_ERROR_ALREADY_INSTALLED,
|
||||
_("This version of %s is already installed"), id);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp (remote, flatpak_deploy_data_get_origin (deploy_data)) != 0)
|
||||
else if (strcmp (remote, flatpak_deploy_data_get_origin (deploy_data)) != 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Can't change remote during bundle install"));
|
||||
return FALSE;
|
||||
if (reinstall)
|
||||
{
|
||||
g_clear_pointer (&deploy_data, g_bytes_unref);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Can't change remote during bundle install"));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10426,7 +10445,7 @@ flatpak_dir_install_bundle (FlatpakDir *self,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!flatpak_dir_deploy_install (self, ref, remote, NULL, NULL, FALSE, FALSE, cancellable, error))
|
||||
if (!flatpak_dir_deploy_install (self, ref, remote, NULL, NULL, reinstall, FALSE, cancellable, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1775,7 +1775,7 @@ flatpak_installation_install_bundle (FlatpakInstallation *self,
|
||||
if (!flatpak_dir_ensure_repo (dir_clone, cancellable, error))
|
||||
return NULL;
|
||||
|
||||
if (!flatpak_dir_install_bundle (dir_clone, file, remote, NULL,
|
||||
if (!flatpak_dir_install_bundle (dir_clone, FALSE, file, remote, NULL,
|
||||
cancellable, error))
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -4892,7 +4892,7 @@ _run_op_kind (FlatpakTransaction *self,
|
||||
op->resolved_metakey, error))
|
||||
res = FALSE;
|
||||
else
|
||||
res = flatpak_dir_install_bundle (priv->dir, op->bundle,
|
||||
res = flatpak_dir_install_bundle (priv->dir, priv->reinstall, op->bundle,
|
||||
op->remote, NULL,
|
||||
cancellable, error);
|
||||
flatpak_transaction_progress_done (progress);
|
||||
|
||||
@@ -1007,6 +1007,7 @@ handle_install_bundle (FlatpakSystemHelper *object,
|
||||
g_autoptr(GFile) bundle_file = g_file_new_for_path (arg_bundle_path);
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(FlatpakDecomposed) ref = NULL;
|
||||
gboolean reinstall;
|
||||
|
||||
g_info ("InstallBundle %s %u %s %s", arg_bundle_path, arg_flags, arg_remote, arg_installation);
|
||||
|
||||
@@ -1031,7 +1032,8 @@ handle_install_bundle (FlatpakSystemHelper *object,
|
||||
return G_DBUS_METHOD_INVOCATION_HANDLED;
|
||||
}
|
||||
|
||||
if (!flatpak_dir_install_bundle (system, bundle_file, arg_remote, &ref, NULL, &error))
|
||||
reinstall = !!(arg_flags & FLATPAK_HELPER_INSTALL_BUNDLE_FLAGS_NO_INTERACTION);
|
||||
if (!flatpak_dir_install_bundle (system, reinstall, bundle_file, arg_remote, &ref, NULL, &error))
|
||||
{
|
||||
flatpak_invocation_return_error (invocation, error, "Error installing bundle");
|
||||
return G_DBUS_METHOD_INVOCATION_HANDLED;
|
||||
|
||||
@@ -48,6 +48,11 @@ ok "create bundles client-side"
|
||||
${FLATPAK} uninstall ${U} -y org.test.Hello >&2
|
||||
${FLATPAK} install ${U} -y --bundle bundles/hello.flatpak >&2
|
||||
|
||||
# Installing again without reinstall option should fail...
|
||||
! ${FLATPAK} install ${U} -y --bundle bundles/hello.flatpak >&2
|
||||
# Now with reinstall option it should pass...
|
||||
${FLATPAK} install ${U} -y --bundle bundles/hello.flatpak --reinstall >&2
|
||||
|
||||
# This should have installed the runtime dependency too
|
||||
assert_has_file $FL_DIR/repo/refs/remotes/test-repo/runtime/org.test.Platform/$ARCH/master
|
||||
|
||||
|
||||
Reference in New Issue
Block a user