mirror of
https://github.com/flatpak/flatpak.git
synced 2026-01-26 22:22:22 +00:00
cli: Automatically install authenticator as needed
This commit is contained in:
parent
f1f2c4844c
commit
b5a9903efc
@ -140,6 +140,49 @@ add_new_remote (FlatpakTransaction *transaction,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
install_authenticator (FlatpakTransaction *old_transaction,
|
||||
const char *remote,
|
||||
const char *ref)
|
||||
{
|
||||
FlatpakCliTransaction *old_cli = FLATPAK_CLI_TRANSACTION (old_transaction);
|
||||
g_autoptr(FlatpakTransaction) transaction2 = NULL;
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
FlatpakInstallation *installation = flatpak_transaction_get_installation (old_transaction);
|
||||
FlatpakDir *dir = flatpak_installation_get_dir (installation, NULL);
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
/* This should not happen */
|
||||
g_warning ("No dir in install_authenticator");
|
||||
return;
|
||||
}
|
||||
|
||||
transaction2 = flatpak_cli_transaction_new (dir, old_cli->disable_interaction, TRUE, FALSE, &local_error);
|
||||
if (transaction2 == NULL)
|
||||
{
|
||||
g_printerr ("Unable to install authenticator: %s\n", local_error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
g_print ("Installing required authenticator for remote %s\n", remote);
|
||||
if (!flatpak_transaction_add_install (transaction2, remote, ref, NULL, &local_error))
|
||||
{
|
||||
if (!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_ALREADY_INSTALLED))
|
||||
g_printerr ("Unable to install authenticator: %s\n", local_error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!flatpak_transaction_run (transaction2, NULL, &local_error))
|
||||
{
|
||||
if (!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_ABORTED))
|
||||
g_printerr ("Unable to install authenticator: %s\n", local_error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static char *
|
||||
op_type_to_string (FlatpakTransactionOperationType operation_type)
|
||||
{
|
||||
@ -1152,6 +1195,7 @@ flatpak_cli_transaction_class_init (FlatpakCliTransactionClass *klass)
|
||||
transaction_class->webflow_start = webflow_start;
|
||||
transaction_class->webflow_done = webflow_done;
|
||||
transaction_class->basic_auth_start = basic_auth_start;
|
||||
transaction_class->install_authenticator = install_authenticator;
|
||||
}
|
||||
|
||||
FlatpakTransaction *
|
||||
|
||||
@ -159,6 +159,47 @@ operation_error (FlatpakTransaction *transaction,
|
||||
return non_fatal; /* Continue if non-fatal */
|
||||
}
|
||||
|
||||
static void
|
||||
install_authenticator (FlatpakTransaction *old_transaction,
|
||||
const char *remote,
|
||||
const char *ref)
|
||||
{
|
||||
g_autoptr(FlatpakTransaction) transaction2 = NULL;
|
||||
g_autoptr(GError) local_error = NULL;
|
||||
FlatpakInstallation *installation = flatpak_transaction_get_installation (old_transaction);
|
||||
FlatpakDir *dir = flatpak_installation_get_dir (installation, NULL);
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
/* This should not happen */
|
||||
g_warning ("No dir in install_authenticator");
|
||||
return;
|
||||
}
|
||||
|
||||
transaction2 = flatpak_quiet_transaction_new (dir, &local_error);
|
||||
if (transaction2 == NULL)
|
||||
{
|
||||
g_printerr ("Unable to install authenticator: %s\n", local_error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!flatpak_transaction_add_install (transaction2, remote, ref, NULL, &local_error))
|
||||
{
|
||||
if (!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_ALREADY_INSTALLED))
|
||||
g_printerr ("Unable to install authenticator: %s\n", local_error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!flatpak_transaction_run (transaction2, NULL, &local_error))
|
||||
{
|
||||
if (!g_error_matches (local_error, FLATPAK_ERROR, FLATPAK_ERROR_ABORTED))
|
||||
g_printerr ("Unable to install authenticator: %s\n", local_error->message);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
end_of_lifed_with_rebase (FlatpakTransaction *transaction,
|
||||
const char *remote,
|
||||
@ -247,6 +288,7 @@ flatpak_quiet_transaction_class_init (FlatpakQuietTransactionClass *class)
|
||||
transaction_class->operation_error = operation_error;
|
||||
transaction_class->end_of_lifed_with_rebase = end_of_lifed_with_rebase;
|
||||
transaction_class->run = flatpak_quiet_transaction_run;
|
||||
transaction_class->install_authenticator = install_authenticator;
|
||||
}
|
||||
|
||||
FlatpakTransaction *
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user